Skip to main content

Bug Tracker

Side navigation

#7695 closed bug (invalid)

Opened December 03, 2010 05:28PM UTC

Closed December 03, 2010 05:58PM UTC

Last modified December 03, 2010 06:33PM UTC

selector [checked] does not work when on applied to a single checkbox

Reported by: JordanClark Owned by:
Priority: undecided Milestone: 1.6
Component: unfiled Version: 1.4.4
Keywords: Cc:
Blocked by: Blocking:
Description

Versioning and affected browsers

In FF, Chrome and Safari, the behavior of the [checked] selector changed from 1.4.2 to 1.4.3, and the same behavior exists in 1.4.4\\\\

IE is not affected by the bug, and exhibits the same behavior from 1.4.2 - 1.4.4\\\\

The browser versions I used are FF 3.6.12, Chrome 7.0.517.44, Safari 5.0.2(7533.18.5), and IE 8.0.6001.18702\\\\

Description

When an element set contains only a single checkbox, adding the adding the additional constraint '[checked]' will never match the element, regardless of the actual checked state.\\\\

When only one checkbox exists,

  $('input[type=checkbox][checked])

and

  $('input[type=checkbox]').filter('[checked]')

have the same results.

\\\\\\\\

If the containing set has at least one element in addition to the checkbox, the result is as expected.

Test case

Test case in 1.4.3: http://jsfiddle.net/8AuPq/3/

Check the checkbox. Line 'box [checked]' will not match the checkbox, but the other three will.\\\\

Repeating the test with 1.4.2 or IE, all lines will match the checkbox.

Attachments (0)
Change History (4)

Changed December 03, 2010 05:37PM UTC by JordanClark comment:1

I forgot to mention in the ticket, but using ':checked' rather than '[checked]' doesn't exhibit this problem, so that's the work-around right there.

But because the behavior is inconsistent across jQuery versions and across browsers using the same version, I thought it was worth reporting.

Changed December 03, 2010 05:58PM UTC by rwaldron comment:2

_comment0: This is not a valid bug \ \ \ http://jsfiddle.net/rwaldron/8AuPq/4/1291399145930244
resolution: → invalid
status: newclosed

This is not a valid bug, please check your attributes list in the input element that you are testing, as well as your selector syntax. Here is a working example:

http://jsfiddle.net/rwaldron/8AuPq/4/

Changed December 03, 2010 06:00PM UTC by snover comment:3

To clarify rwaldron’s comment, checking a checkbox does ''not'' change the checked attribute, it just changes the state of the object in memory. :checked works because it inspects the DOM HTML property, not the attribute, and [checked] works in IE because Sizzle inspects DOM HTML properties when it should not. The disparity between IE and other browsers will be resolved in 1.5, at which point [checked] will function identically to all other browsers.

Changed December 03, 2010 06:33PM UTC by JordanClark comment:4

Thanks for the clarification snover - that makes perfect sense.

The only part I still don't understand is why [checked] doesn't work with a single element in the matched set, but does work when there is more than one element. Shouldn't the selector work the same way regardless of the number of elements in the set?