Skip to main content

Bug Tracker

Side navigation

#7194 closed feature (wontfix)

Opened October 14, 2010 10:56PM UTC

Closed June 06, 2011 06:48PM UTC

Last modified June 21, 2011 06:09PM UTC

Suggested selector/function .or()

Reported by: addyosmani Owned by: rwaldron
Priority: low Milestone: 1.7
Component: selector Version: 1.4.3
Keywords: Cc:
Blocked by: Blocking:
Description

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/

Attachments (0)
Change History (19)

Changed October 14, 2010 11:58PM UTC by snover comment:1

component: unfiledselector
keywords: → needsreview
priority: undecidedlow

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

Changed October 15, 2010 06:53AM UTC by naugtur comment:2

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)

Changed November 12, 2010 02:40AM UTC by snover comment:3

milestone: 1.4.3

Resetting milestone to future.

Changed November 20, 2010 03:26AM UTC by dmethvin comment:4

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).

Changed April 07, 2011 02:16PM UTC by dmethvin comment:5

milestone: → 1.7
owner: → dmethvin
status: newassigned

Changed April 16, 2011 10:58PM UTC by john comment:6

milestone: 1.71.next
owner: dmethvin

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.

Changed May 22, 2011 07:27PM UTC by john comment:7

keywords: needsreviewneedsreview,1.7-discuss

Nominating ticket for 1.7 discussion.

Changed May 22, 2011 09:43PM UTC by rwaldron comment:8

description: 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/] \ 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/]\

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

Changed May 22, 2011 10:02PM UTC by rwaldron comment:9

description: 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/]\ 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/] \
owner: → rwaldron

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

Changed May 23, 2011 12:14AM UTC by jaubourg comment:10

description: 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/] \ 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/]\

-1, we don't need other helpers in core. Let's make an official plugin for all these.

Changed May 23, 2011 03:51AM UTC by timmywil comment:11

-1, sounds like a feature creep

Changed May 23, 2011 03:42PM UTC by ajpiano comment:12

description: 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/]\ 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/] \

+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.

Changed June 03, 2011 01:40PM UTC by john comment:13

description: 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/] \ 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/]\

+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).

Changed June 03, 2011 01:46PM UTC by addyosmani comment:14

description: 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/]\ 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/] \

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.

Changed June 03, 2011 03:26PM UTC by scottgonzalez comment:15

description: 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/] \ 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/]\

-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.

Changed June 06, 2011 03:57PM UTC by jzaefferer comment:16

-1

Changed June 06, 2011 05:12PM UTC by danheberden comment:17

description: 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/]\ 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/] \

-1, plugin

Changed June 06, 2011 06:48PM UTC by rwaldron comment:18

keywords: needsreview,1.7-discuss
milestone: 1.next1.7
resolution: → wontfix
status: assignedclosed

Needs to prove itself as a widely adopted plugin

Changed June 21, 2011 06:09PM UTC by rwaldron comment:19

#9638 is a duplicate of this ticket.