Ticket #7194 (closed feature: wontfix)
Suggested selector/function .or()
| Reported by: | addyosmani | Owned by: | rwaldron |
|---|---|---|---|
| Priority: | low | Milestone: | 1.7 |
| Component: | selector | Version: | 1.4.3 |
| Keywords: | Cc: | ||
| Blocking: | Blocked by: |
Description (last modified by danheberden) (diff)
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
comment:1 Changed 3 years ago by snover
- Keywords needsreview added
- Priority changed from undecided to low
- Component changed from unfiled to selector
comment:2 Changed 3 years ago by naugtur
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 3 years ago by dmethvin
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 2 years ago by dmethvin
- Owner set to dmethvin
- Status changed from new to assigned
- Milestone set to 1.7
comment:6 Changed 2 years ago by john
- Owner dmethvin deleted
- Milestone changed from 1.7 to 1.next
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:7 Changed 2 years ago by john
- Keywords needsreview,1.7-discuss added; needsreview removed
Nominating ticket for 1.7 discussion.
comment:8 Changed 2 years ago by rwaldron
- Description modified (diff)
+1, I'm beginning to like the idea; dislike the implementation
comment:9 Changed 2 years ago by rwaldron
- Owner set to rwaldron
- Description modified (diff)
Simpler implementation + unit tests: http://jsfiddle.net/rwaldron/LNC5m/
comment:10 Changed 2 years ago by jaubourg
- Description modified (diff)
-1, we don't need other helpers in core. Let's make an official plugin for all these.
comment:11 Changed 2 years ago by timmywil
-1, sounds like a feature creep
comment:12 Changed 2 years ago by ajpiano
- 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 2 years ago by john
- 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 2 years ago by addyosmani
- 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 2 years ago by scott.gonzalez
- 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:16 Changed 2 years ago by jzaefferer
-1
comment:18 Changed 2 years ago by rwaldron
- Keywords needsreview,1.7-discuss removed
- Status changed from assigned to closed
- Resolution set to wontfix
- Milestone changed from 1.next to 1.7
Needs to prove itself as a widely adopted plugin
comment:19 Changed 2 years ago by rwaldron
#9638 is a duplicate of this ticket.
Please follow the bug reporting guidlines and use jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

Smells like bikeshed/feature creep to me, so placing in review.