Bug Tracker

Modify

Ticket #4302 (closed bug: worksforme)

Opened 4 years ago

Last modified 3 years ago

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

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

Change History

comment:1 Changed 4 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 4 years ago by scott_h

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.

View

Add a comment

Modify Ticket

Action
as closed
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.