Skip to main content

Bug Tracker

Side navigation

#8075 closed feature (fixed)

Opened January 27, 2011 02:28PM UTC

Closed May 03, 2011 07:01PM UTC

Last modified March 13, 2012 06:04PM UTC

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:

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 )) ) {


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?

Attachments (0)
Change History (12)

Changed January 27, 2011 05:26PM UTC by jitter comment:1

component: unfiledtraversing
priority: undecidedhigh

Changed January 27, 2011 05:26PM UTC by jitter comment:2

priority: highlow

Changed January 27, 2011 05:29PM UTC by jitter comment:3

owner: → anonymous
status: newpending

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

Changed January 28, 2011 02:49PM UTC by anonymous comment:4

status: pendingnew

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

Changed February 02, 2011 03:11AM UTC by jitter comment:5


Changed February 06, 2011 04:08PM UTC by snover comment:7

milestone: 1.next1.6
priority: lowhigh
status: newopen

Increasing priority & retargeting due to potential performance benefits.

Changed April 16, 2011 09:58PM UTC by john comment:8

owner: anonymous
status: openassigned

Let's look at this for 1.7.

Changed May 03, 2011 06:43PM UTC by JRSchild comment:9

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




Should the documentation and test-cases be updated?

Changed May 03, 2011 07:01PM UTC by timmywil comment:10

keywords: → needsdocs
milestone: 1.next1.6
resolution: → fixed
status: assignedclosed
type: enhancementfeature

Good point! Thanks JRSchild

Changed June 08, 2011 05:38AM UTC by addyosmani comment:11

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

Changed June 13, 2011 05:08AM UTC by addyosmani comment:12

keywords: needsdocsneededdocs

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