Side navigation
#4446 closed enhancement (wontfix)
Opened March 29, 2009 10:15PM UTC
Closed July 11, 2011 06:56PM UTC
.andSelf(selector)
Reported by: | karamfil | Owned by: | |
---|---|---|---|
Priority: | low | Milestone: | 1.next |
Component: | traversing | Version: | 1.3.2 |
Keywords: | andSelf,filter,1.7-discuss | Cc: | |
Blocked by: | Blocking: |
Description
Why not andSelf() function to have a selector param. Here is a particular example
$('element').nextAll('.className').andSelf('.className').doSomething();
This way one can add self only if it meets particular requirements.
Here is a fast solution :)
$.fn.andSelf = function(selector){ return (selector == null || this.prevObject.is(selector)) ? this.add( this.prevObject ) : this; }
Attachments (0)
Change History (23)
Changed April 01, 2009 11:53PM UTC by comment:1
Changed May 03, 2009 08:42PM UTC by comment:2
description: | Why not andSelf() function to have a selector param. Here is a particular example \ \ $('element').nextAll('.className').andSelf('.className').doSomething(); \ \ This way one can add self only if it meets particular requirements. \ \ Here is a fast solution :) \ \ $.fn.andSelf = function(selector){ return (selector == null || this.prevObject.is(selector)) ? this.add( this.prevObject ) : this; } → Why not andSelf() function to have a selector param. Here is a particular example \ {{{ \ $('element').nextAll('.className').andSelf('.className').doSomething(); \ }}} \ This way one can add self only if it meets particular requirements. \ \ Here is a fast solution :) \ \ {{{ \ $.fn.andSelf = function(selector){ return (selector == null || this.prevObject.is(selector)) ? this.add( this.prevObject ) : this; } \ }}} |
---|
Changed June 23, 2010 03:42PM UTC by comment:3
I would find this feature very useful. It seems like an appropriate change to to bring andSelf() in line with the other traversal methods.
Changed November 03, 2010 02:55PM UTC by comment:4
Assuming the provided code functions I think this would be a reasonable candidate for the next version. I can think of some use cases where this might be handy, although I've never needed it in the past.
Changed November 03, 2010 06:15PM UTC by comment:5
keywords: | andSelf → andSelf filter |
---|---|
milestone: | 1.4 → 1.5 |
priority: | minor → low |
status: | new → open |
Changed November 21, 2010 02:10AM UTC by comment:6
component: | core → traversing |
---|
Changed January 23, 2011 07:13PM UTC by comment:7
I've submitted a pull request which implements this: https://github.com/jquery/jquery/pull/203
Changed April 16, 2011 09:49PM UTC by comment:9
milestone: | → 1.next |
---|
Let's consider this for 1.7.
Changed May 22, 2011 07:27PM UTC by comment:10
keywords: | andSelf filter → andSelf,filter,1.7-discuss |
---|
Nominating ticket for 1.7 discussion.
Changed May 22, 2011 09:58PM UTC by comment:11
+1, I like the feature but maybe we can find something better than .andSelf()
to describe it?
Changed May 22, 2011 10:30PM UTC by comment:12
description: | Why not andSelf() function to have a selector param. Here is a particular example \ {{{ \ $('element').nextAll('.className').andSelf('.className').doSomething(); \ }}} \ This way one can add self only if it meets particular requirements. \ \ Here is a fast solution :) \ \ {{{ \ $.fn.andSelf = function(selector){ return (selector == null || this.prevObject.is(selector)) ? this.add( this.prevObject ) : this; } \ }}} → Why not andSelf() function to have a selector param. Here is a particular example\ {{{\ $('element').nextAll('.className').andSelf('.className').doSomething();\ }}}\ This way one can add self only if it meets particular requirements.\ \ Here is a fast solution :)\ \ {{{\ $.fn.andSelf = function(selector){ return (selector == null || this.prevObject.is(selector)) ? this.add( this.prevObject ) : this; }\ }}} |
---|
+0,
Changed May 22, 2011 11:41PM UTC by comment:13
-1, I'd like these kind of helpers to be added into an official plugin, not be put in core.
Changed May 23, 2011 01:44AM UTC by comment:14
description: | Why not andSelf() function to have a selector param. Here is a particular example\ {{{\ $('element').nextAll('.className').andSelf('.className').doSomething();\ }}}\ This way one can add self only if it meets particular requirements.\ \ Here is a fast solution :)\ \ {{{\ $.fn.andSelf = function(selector){ return (selector == null || this.prevObject.is(selector)) ? this.add( this.prevObject ) : this; }\ }}} → Why not andSelf() function to have a selector param. Here is a particular example \ {{{ \ $('element').nextAll('.className').andSelf('.className').doSomething(); \ }}} \ This way one can add self only if it meets particular requirements. \ \ Here is a fast solution :) \ \ {{{ \ $.fn.andSelf = function(selector){ return (selector == null || this.prevObject.is(selector)) ? this.add( this.prevObject ) : this; } \ }}} |
---|
-1, .andSelf should do what it says.
Changed May 23, 2011 02:44AM UTC by comment:15
description: | Why not andSelf() function to have a selector param. Here is a particular example \ {{{ \ $('element').nextAll('.className').andSelf('.className').doSomething(); \ }}} \ This way one can add self only if it meets particular requirements. \ \ Here is a fast solution :) \ \ {{{ \ $.fn.andSelf = function(selector){ return (selector == null || this.prevObject.is(selector)) ? this.add( this.prevObject ) : this; } \ }}} → Why not andSelf() function to have a selector param. Here is a particular example\ {{{\ $('element').nextAll('.className').andSelf('.className').doSomething();\ }}}\ This way one can add self only if it meets particular requirements.\ \ Here is a fast solution :)\ \ {{{\ $.fn.andSelf = function(selector){ return (selector == null || this.prevObject.is(selector)) ? this.add( this.prevObject ) : this; }\ }}} |
---|
+0, plugin
Changed May 23, 2011 03:19PM UTC by comment:16
+1, Seems reasonable since most other stack addition functions take a selector
Changed May 23, 2011 05:15PM UTC by comment:17
description: | Why not andSelf() function to have a selector param. Here is a particular example\ {{{\ $('element').nextAll('.className').andSelf('.className').doSomething();\ }}}\ This way one can add self only if it meets particular requirements.\ \ Here is a fast solution :)\ \ {{{\ $.fn.andSelf = function(selector){ return (selector == null || this.prevObject.is(selector)) ? this.add( this.prevObject ) : this; }\ }}} → Why not andSelf() function to have a selector param. Here is a particular example \ {{{ \ $('element').nextAll('.className').andSelf('.className').doSomething(); \ }}} \ This way one can add self only if it meets particular requirements. \ \ Here is a fast solution :) \ \ {{{ \ $.fn.andSelf = function(selector){ return (selector == null || this.prevObject.is(selector)) ? this.add( this.prevObject ) : this; } \ }}} |
---|
-1
Changed June 03, 2011 01:08PM UTC by comment:18
description: | Why not andSelf() function to have a selector param. Here is a particular example \ {{{ \ $('element').nextAll('.className').andSelf('.className').doSomething(); \ }}} \ This way one can add self only if it meets particular requirements. \ \ Here is a fast solution :) \ \ {{{ \ $.fn.andSelf = function(selector){ return (selector == null || this.prevObject.is(selector)) ? this.add( this.prevObject ) : this; } \ }}} → Why not andSelf() function to have a selector param. Here is a particular example\ {{{\ $('element').nextAll('.className').andSelf('.className').doSomething();\ }}}\ This way one can add self only if it meets particular requirements.\ \ Here is a fast solution :)\ \ {{{\ $.fn.andSelf = function(selector){ return (selector == null || this.prevObject.is(selector)) ? this.add( this.prevObject ) : this; }\ }}} |
---|
-1, I don't really agree with the API change.
Changed June 03, 2011 02:08PM UTC by comment:19
+0, I'm torn on this one. No strong feelings either way.
Changed June 04, 2011 10:14PM UTC by comment:20
-1
Changed June 06, 2011 03:34PM UTC by comment:21
+1, useful, and provides consistent optional filtering for traversing methods
Changed June 06, 2011 03:40PM UTC by comment:22
+1, Doing this would not only be cool, it would make #4596 a non-issue (see my comment there)
Changed July 11, 2011 06:56PM UTC by comment:23
description: | Why not andSelf() function to have a selector param. Here is a particular example\ {{{\ $('element').nextAll('.className').andSelf('.className').doSomething();\ }}}\ This way one can add self only if it meets particular requirements.\ \ Here is a fast solution :)\ \ {{{\ $.fn.andSelf = function(selector){ return (selector == null || this.prevObject.is(selector)) ? this.add( this.prevObject ) : this; }\ }}} → Why not andSelf() function to have a selector param. Here is a particular example \ {{{ \ $('element').nextAll('.className').andSelf('.className').doSomething(); \ }}} \ This way one can add self only if it meets particular requirements. \ \ Here is a fast solution :) \ \ {{{ \ $.fn.andSelf = function(selector){ return (selector == null || this.prevObject.is(selector)) ? this.add( this.prevObject ) : this; } \ }}} |
---|---|
resolution: | → wontfix |
status: | open → closed |
Watch out there. The
method only checks the first element in the jQuery object. I think you'd want instead. Probably the name isn't clear enough but at this point I guess we're stuck with it. The enhancement seems useful though.