#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 12 years ago by
Component: | unfiled → traversing |
---|---|
Priority: | undecided → high |
comment:2 Changed 12 years ago by
Priority: | high → low |
---|
comment:3 Changed 12 years ago by
Owner: | set to anonymous |
---|---|
Status: | new → pending |
comment:4 Changed 12 years ago by
Status: | pending → new |
---|
http://jsperf.com/nextuntil-tests
Created a small perf on this ticket. I think it could be optimized and enhanced.
comment:5 Changed 12 years ago by
Version: | 1.4.4 → 1.5 |
---|
comment:6 Changed 12 years ago by
comment:7 Changed 12 years ago by
Milestone: | 1.next → 1.6 |
---|---|
Priority: | low → high |
Status: | new → open |
Increasing priority & retargeting due to potential performance benefits.
comment:8 Changed 12 years ago by
Milestone: | 1.6 → 1.next |
---|---|
Owner: | anonymous deleted |
Status: | open → assigned |
Let's look at this for 1.7.
comment:9 Changed 12 years ago by
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 12 years ago by
Keywords: | needsdocs added |
---|---|
Milestone: | 1.next → 1.6 |
Resolution: | → fixed |
Status: | assigned → closed |
Type: | enhancement → feature |
Good point! Thanks JRSchild
comment:11 Changed 12 years ago by
Working on this at the moment. We'll make sure to post updated examples, signatures and wordage, JRSchild. Thanks!
comment:12 Changed 12 years ago by
Keywords: | neededdocs added; needsdocs removed |
---|
I've updated the docs on .nextUntil(), .prevUntil() and .parentsUntil() to reflect the changes in behaviour.
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