Bug Tracker

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 Rick Waldron)

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 snover

Component: unfiledselector
Keywords: needsreview added
Priority: undecidedlow

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

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

Milestone: 1.4.3

Resetting milestone to future.

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

Milestone: 1.7
Owner: set to dmethvin
Status: newassigned

comment:6 Changed 11 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 11 years ago by john

Keywords: 1.7-discuss added

Nominating ticket for 1.7 discussion.

comment:8 Changed 11 years ago by Rick Waldron

Description: modified (diff)

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

comment:9 Changed 11 years ago by Rick Waldron

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

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

Note: See TracTickets for help on using tickets.