Ticket #4428 (closed bug: invalid)
SELECTOR doesn't work
| Reported by: | simonxy | Owned by: | john |
|---|---|---|---|
| Priority: | critical | Milestone: | 1.4 |
| Component: | selector | Version: | 1.3.2 |
| Keywords: | Cc: | ||
| Blocking: | Blocked by: |
Description
If I use the following selector:
$('~ span:first', this) doesn't work - it won't found any element. (this is input element, but it doesn't matter)
If I remove :first, than it works. $('~ span', this) - THIS WORKS.
In old library 1.2.1.js the first example works: $('~ span:first', this) - THIS WORKS IN PREVIOUS LIBRARY.
Attachments
Change History
Changed 4 years ago by simonxy
-
attachment
bamboo.zip
added
Changed 4 years ago by petersendidit
-
attachment
testcase.html
added
here is a simplified test case that shows the seelctor problem.
comment:1 Changed 3 years ago by addyosmani
- Status changed from new to closed
- Resolution set to invalid
Your test case is using invalid HTML (for this particular problem) which is why your code is likely failing. If you wish to find a child element belong to a particular parent, you need to have that child actually be a child *of that parent* rather than outside of it. Not doing so would render your test case to not function correctly which is what is happening here.
comment:2 Changed 3 years ago by jitter
Why would his HTML be invalid? He doesn't want to find a child, he wants to find a sibling. ~ is the Next Siblings Selector.
In this case he wants to find all/first span sibling of every div.
I made a test case. If you switch between the various jQuery version you will notice that
jQuery 1.2.6 returned 1 for all tests
jQuery 1.3.2 returns 0 for Test 2 and Test 4
jQuery 1.4.3 fails to return 1 for all tests but Test 5.
This is a serious regression getting worse since jQuery 1.2.6
Please follow the bug reporting guidlines and use jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

example of this selector