Bug Tracker

Opened 9 years ago

Closed 8 years ago

Last modified 8 years ago

#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 danheberden)

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 9 years ago by snover

Component: unfiledselector
Keywords: needsreview added
Priority: undecidedlow

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

comment:2 Changed 9 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:3 Changed 9 years ago by snover

Milestone: 1.4.3

Resetting milestone to future.

comment:4 Changed 9 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 8 years ago by dmethvin

Milestone: 1.7
Owner: set to dmethvin
Status: newassigned

comment:6 Changed 8 years ago by john

Milestone: 1.71.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:7 Changed 8 years ago by john

Keywords: 1.7-discuss added

Nominating ticket for 1.7 discussion.

comment:8 Changed 8 years ago by Rick Waldron

Description: modified (diff)

+1, I'm beginning to like the idea; dislike the implementation

comment:9 Changed 8 years ago by Rick Waldron

Description: modified (diff)
Owner: set to Rick Waldron

Simpler implementation + unit tests: http://jsfiddle.net/rwaldron/LNC5m/

comment:10 Changed 8 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 8 years ago by timmywil

-1, sounds like a feature creep

comment:12 Changed 8 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 8 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 8 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 8 years ago by scottgonzalez

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 8 years ago by jzaefferer

-1

comment:17 Changed 8 years ago by danheberden

Description: modified (diff)

-1, plugin

comment:18 Changed 8 years ago by Rick Waldron

Keywords: needsreview 1.7-discuss removed
Milestone: 1.next1.7
Resolution: wontfix
Status: assignedclosed

Needs to prove itself as a widely adopted plugin

comment:19 Changed 8 years ago by Rick Waldron

#9638 is a duplicate of this ticket.

Note: See TracTickets for help on using tickets.