Bug Tracker

Opened 9 years ago

Closed 8 years ago

Last modified 8 years ago

#8075 closed feature (fixed)

nextUntil, prevUntil and parentsUntil should accept more then just selectors

Reported by: anonymous Owned by:
Priority: high Milestone: 1.6
Component: traversing Version: 1.5
Keywords: neededdocs Cc:
Blocked by: Blocking:

Description

Just as the title says. One way to make sure the "Until" methods accept more then just selectors is to use the filter method instead of jQuery().is from line 4556 from:

while ( cur && cur.nodeType !== 9 && ( until === undefined || cur.nodeType !== 1 || !jQuery( cur ).is( until )) ) {

To:

while ( cur && cur.nodeType !== 9 && ( until === undefined || cur.nodeType !== 1 || !jQuery( cur ).filter(until)[0] )) {

Now, correct me if I'm wrong here. But assuming you are comparing two DOM nodes to each other. Wouldn't it be a lot faster to compare those right away, so a new jQuery instance won't be created on each iteration? This way you would get something like:

while ( cur && cur.nodeType !== 9 && ( until === undefined || cur.nodeType !== 1 || !( cur === until || jQuery( cur ).filter( until )[0])) ) {

Heck, we could even use matchesSelector between them with something like this:

!( cur === until || ( typeof until === "string" && jQuery.find.matchesSelector( cur, until ) ) || jQuery( cur ).filter( until )[0])

Any thoughts?

Change History (12)

comment:1 Changed 9 years ago by jitter

Component: unfiledtraversing
Priority: undecidedhigh

comment:2 Changed 9 years ago by jitter

Priority: highlow

comment:3 Changed 9 years ago by jitter

Owner: set to anonymous
Status: newpending

To increase the chances for this to make into the core you should make a pull request with the needed changes


http://docs.jquery.com/Tips_for_jQuery_Bug_Patching
http://docs.jquery.com/Getting_Involved

comment:4 Changed 9 years ago by anonymous

Status: pendingnew

http://jsperf.com/nextuntil-tests

Created a small perf on this ticket. I think it could be optimized and enhanced.

comment:5 Changed 9 years ago by jitter

Version: 1.4.41.5

comment:7 Changed 9 years ago by snover

Milestone: 1.next1.6
Priority: lowhigh
Status: newopen

Increasing priority & retargeting due to potential performance benefits.

comment:8 Changed 8 years ago by john

Milestone: 1.61.next
Owner: anonymous deleted
Status: openassigned

Let's look at this for 1.7.

comment:9 Changed 8 years ago by JRSchild

As of jQuery 1.6 and the updated is() and find() methods this already works:

nextUntil: http://jsfiddle.net/asz7m/
prevUntil: http://jsfiddle.net/mXmSS/
parentsUntil: http://jsfiddle.net/n77ua/

Should the documentation and test-cases be updated?

comment:10 Changed 8 years ago by timmywil

Keywords: needsdocs added
Milestone: 1.next1.6
Resolution: fixed
Status: assignedclosed
Type: enhancementfeature

Good point! Thanks JRSchild

comment:11 Changed 8 years ago by addyosmani

Working on this at the moment. We'll make sure to post updated examples, signatures and wordage, JRSchild. Thanks!

comment:12 Changed 8 years ago by addyosmani

Keywords: neededdocs added; needsdocs removed

I've updated the docs on .nextUntil(), .prevUntil() and .parentsUntil() to reflect the changes in behaviour.

Note: See TracTickets for help on using tickets.