Modify ↓
Ticket #4302 (closed bug: worksforme)
jQuery doesn't filter (and probably everything else) child selector properly
| Reported by: | vidmich | Owned by: | john |
|---|---|---|---|
| Priority: | major | Milestone: | 1.4 |
| Component: | selector | Version: | 1.3.1 |
| Keywords: | Cc: | ||
| Blocking: | Blocked by: |
Description
jQuery('<div><div class="cls1"><div class="cls2"><div><div class="cls2"><div class="cls3"></div></div></div></div></div></div>').find('.cls1 > .cls2 .cls3').length === 1
should be true
having elements with classes .cls1 .cls2 .cls2 .cls3 selector '.cls1 > .cls2 .cls3' returns 0 elements
propably cause jQuery stop searching correct pattern of parents when found that nearset .cls2 parent have no .cls1 parent...
Attachments
Change History
comment:2 Changed 3 years ago by dmethvin
- Status changed from new to closed
- Resolution set to worksforme
http://jsfiddle.net/dmethvin/uEL2c/
Must have been fixed at some point.
Please follow the bug reporting guidlines and use jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.
Note: See
TracTickets for help on using
tickets.


I've encountered this bug too. Here are my findings:
It looks like >, + and ~ combinators are too pessimistic -- if they fail to match on the first element they're tested against, jQuery will refuse to test any ancestors.
I've created a test case but there are many more subtleties my test case doesn't capture. Consider testing the selector '.a > .b > .c *' against the DOM tree represented by '.a > .b > .b.c > .c > x' -- when '.a' fails to match on .b, it needs to backtrack one element and resume testing from '.c' to find the match. Chains of > and + need to be treated like units.