Bug Tracker

Opened 6 years ago

Closed 6 years ago

#12830 closed bug (duplicate)

find('option[selected]') and find('option').filter('[selected]') give different results

Reported by: pang@… Owned by:
Priority: low Milestone: 1.9
Component: selector Version: 1.8.2
Keywords: Cc:
Blocked by: Blocking:

Description

  • Bug Description:
find('option[selected]')

and

find('option').filter('[selected]')

give different results after user changed selection in dropdown manually. I believe that they are just 2 different ways to write the same expression and therefore should always return the same result.

  • jQuery versions: 1.8.2, 1.7.2, 1.6.4
  • Browsers: Chrome, Firefox, IE9, Opera, Safari
  • OS: Windows, Mac, iOS
  • Live demo: http://jsfiddle.net/ugXtx/9/
  • Expected behaviour: The 2 different jQuery expressions always give the same result.
  • Actual behaviour: They give different results after user changed selection in dropdown manually
  • Steps to reproduce:
    1. Go to Live demo (see link above)
    2. Choose any option in select dropdown (other than default option)
    3. Click button to trigger the jQuery expressions.
    4. Result is shown

As you can see, they are different.

  • More details (source code, test results, discussion, etc.): http://stackoverflow.com/questions/13137737
  • Note: I know I can use :selected to get the current selection, but that's not the point. The point is that jQuery (or Sizzle?) behave inconsistently when the same selector is written in different ways.

Change History (2)

comment:1 Changed 6 years ago by dmethvin

Component: unfiledselector
Milestone: None1.9
Priority: undecidedlow
Status: newopen

comment:2 Changed 6 years ago by gibson042

Resolution: duplicate
Status: openclosed

Duplicate of #11115.
Ah, the boolHook rears its ugly head: http://jsfiddle.net/ugXtx/13/

querySelectorAll gets it right, and jQuery.attr doesn't.

Note: See TracTickets for help on using tickets.