Opened 12 years ago
Last modified 11 years ago
#7194 closed feature
Suggested selector/function .or() — at Version 9
Reported by: | addyosmani | Owned by: | Rick Waldron |
---|---|---|---|
Priority: | low | Milestone: | 1.7 |
Component: | selector | Version: | 1.4.3 |
Keywords: | Cc: | ||
Blocked by: | Blocking: |
Description (last modified by )
From: http://forum.jquery.com/topic/traversing-or#14737000001495015 A suggestion for including support for or()
.or( [selector/function] ) The method allows comfortable handling of situations where a selector is not matched.
Suggested code:
$.fn.or=function(a){var t=this;return t.length>0?t:(t=t.end())&&$.isFunction(a)?a.apply(t):a?t.find(a):t}
Additional use and test cases can be found here: http://www.jsfiddle.net/naugtur/rdEAu/
Change History (9)
comment:1 Changed 12 years ago by
Component: | unfiled → selector |
---|---|
Keywords: | needsreview added |
Priority: | undecided → low |
comment:2 Changed 12 years ago by
I have fixed the misbehaviour stated in examples. I will update the jsFiddle page soon.
The fix is about .or() being able to use the most recent traversing method so that it's more intuitive (and makes sense when a chain with .or is read aloud)
comment:4 Changed 12 years ago by
A couple of times long ago I used $("#id1").add("#id2").eq(0)
to get #id2 if #id1 doesn't exist, but that depended on .add appending the element to the set and I'm not sure it's good to depend on that (it may use document order).
comment:5 Changed 11 years ago by
Milestone: | → 1.7 |
---|---|
Owner: | set to dmethvin |
Status: | new → assigned |
comment:6 Changed 11 years ago by
Milestone: | 1.7 → 1.next |
---|---|
Owner: | dmethvin deleted |
This proposal has been coming up since the beginning of jQuery. Let's stick this in the roadmap review for 1.7 and figure it out once and for all.
comment:8 Changed 11 years ago by
Description: | modified (diff) |
---|
+1, I'm beginning to like the idea; dislike the implementation
comment:9 Changed 11 years ago by
Description: | modified (diff) |
---|---|
Owner: | set to Rick Waldron |
Simpler implementation + unit tests: http://jsfiddle.net/rwaldron/LNC5m/
Smells like bikeshed/feature creep to me, so placing in review.