Bug Tracker

Opened 14 years ago

Closed 12 years ago

#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:
Blocked by: Blocking:


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 (1)

pessimistic_combinators.html (1.8 KB) - added by scott_h 14 years ago.

Download all attachments as: .zip

Change History (3)

comment:1 Changed 14 years ago by scott_h

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.

Changed 14 years ago by scott_h

comment:2 Changed 12 years ago by dmethvin

Resolution: worksforme
Status: newclosed


Must have been fixed at some point.

Note: See TracTickets for help on using tickets.