#7194 closed feature (wontfix)
Suggested selector/function .or()
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 (19)
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 12 years ago by
Milestone: | → 1.7 |
---|---|
Owner: | set to dmethvin |
Status: | new → assigned |
comment:6 Changed 12 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 12 years ago by
Description: | modified (diff) |
---|
+1, I'm beginning to like the idea; dislike the implementation
comment:9 Changed 12 years ago by
Description: | modified (diff) |
---|---|
Owner: | set to Rick Waldron |
Simpler implementation + unit tests: http://jsfiddle.net/rwaldron/LNC5m/
comment:10 Changed 12 years ago by
Description: | modified (diff) |
---|
-1, we don't need other helpers in core. Let's make an official plugin for all these.
comment:12 Changed 12 years ago by
Description: | modified (diff) |
---|
+0, Are there really a lot of situations where people should be writing code that just is appropriate for different elements depending on which is there? It's not a tonne of code, and seems people want it, but also a bit confusing. I'm on the fence.
comment:13 Changed 12 years ago by
Description: | modified (diff) |
---|
+0, Ehhh... I'm really hesitant to just add this straight in. A lot more thought should go into it (building off of whatever expression happened last, for example).
comment:14 Changed 12 years ago by
Description: | modified (diff) |
---|
I'm going to +0/-1 this one too. On reflection it's not something I still feel should belong in core in it's current state.
comment:15 Changed 12 years ago by
Description: | modified (diff) |
---|
-1, This is one of the most difficult to immediately understand APIs. I would expect a ton of confusion by users about $( ".a" ).or( ".b" ) vs. $( ".a" ).add( ".b" ) vs. $( ".a, .b" ). I've definitely had use cases for this, but this is far from a pain point and not too common.
comment:18 Changed 12 years ago by
Keywords: | needsreview 1.7-discuss removed |
---|---|
Milestone: | 1.next → 1.7 |
Resolution: | → wontfix |
Status: | assigned → closed |
Needs to prove itself as a widely adopted plugin
Smells like bikeshed/feature creep to me, so placing in review.