Skip to main content

Bug Tracker

Side navigation

#8977 closed bug (invalid)

Opened April 26, 2011 01:26PM UTC

Closed April 26, 2011 02:46PM UTC

:checked attribute returning the first value, even after changes

Reported by: <kantorvv@gmail.com> Owned by: <kantorvv@gmail.com>
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>
Attachments (0)
Change History (2)

Changed April 26, 2011 02:00PM UTC by rwaldron comment:1

component: unfiledattributes
owner: → <kantorvv@gmail.com>
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.

Changed April 26, 2011 02:46PM UTC by timmywil comment:2

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').