Bug Tracker

Opened 10 years ago

Closed 10 years ago

#8977 closed bug (invalid)

:checked attribute returning the first value, even after changes

Reported by: <kantorvv@…> Owned by: <kantorvv@…>
Priority: low Milestone: 1.next
Component: attributes Version: 1.6b1
Keywords: Cc:
Blocked by: Blocking:

Description

<input type="checkbox" checked="checked" id="sure"/>
<input type="checkbox" id="unsure"/>
<script>
 $('#sure,#unsure').change(function(){
            console.log($('#sure').attr('checked'),$('#unsure').attr('checked'));
 })

//1.6b1
$("#unsure").trigger('change') // checked undefined
$("#unsure").trigger('change') // checked undefined

//1.5.2
$("#unsure").trigger('change') // true true
$("#unsure").trigger('change') // true false
</script>

Change History (2)

comment:1 Changed 10 years ago by Rick Waldron

Component: unfiledattributes
Owner: set to <kantorvv@…>
Status: newpending

Thanks for taking the time to contribute to the jQuery project! Please provide a reduced jsFiddle test case to help us assess your ticket!

Additionally, be sure to test against the jQuery Edge version to ensure the issue still exists.

comment:2 Changed 10 years ago by timmywil

Priority: undecidedlow
Resolution: invalid
Status: pendingclosed

That is the correct behavior. This is something that was fixed in attr in 1.6 (removing the ambiguity). .attr('checked') retrieves the actual attribute (which correctly returns undefined as it does not exist on unsure) rather than the property. For DOM properties, use the .prop method. However, the preferred way to check if a box is checked, is with .is(':checked').

Note: See TracTickets for help on using tickets.