Skip to main content

Bug Tracker

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 dmethvin comment:1

Watch out there. The

.is()
method only checks the first element in the jQuery object. I think you'd want
.filter()
instead. Probably the
.andSelf()
name isn't clear enough but at this point I guess we're stuck with it. The enhancement seems useful though.

Changed May 03, 2009 08:42PM UTC by brandon 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 scottsb 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 boushley 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 SlexAxton comment:5

keywords: andSelfandSelf filter
milestone: 1.41.5
priority: minorlow
status: newopen

Changed November 21, 2010 02:10AM UTC by dmethvin comment:6

component: coretraversing

Changed January 23, 2011 07:13PM UTC by gg comment:7

I've submitted a pull request which implements this: https://github.com/jquery/jquery/pull/203

Changed March 21, 2011 07:54PM UTC by addyosmani comment:8

#6966 is a duplicate of this ticket.

Changed April 16, 2011 09:49PM UTC by john comment:9

milestone: → 1.next

Let's consider this for 1.7.

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

keywords: andSelf filterandSelf,filter,1.7-discuss

Nominating ticket for 1.7 discussion.

Changed May 22, 2011 09:58PM UTC by dmethvin 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 rwaldron 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 jaubourg 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 ajpiano 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 timmywil 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 danheberden comment:16

+1, Seems reasonable since most other stack addition functions take a selector

Changed May 23, 2011 05:15PM UTC by paul.irish 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 john 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 scottgonzalez comment:19

+0, I'm torn on this one. No strong feelings either way.

Changed June 04, 2011 10:14PM UTC by addyosmani comment:20

-1

Changed June 06, 2011 03:34PM UTC by jzaefferer comment:21

+1, useful, and provides consistent optional filtering for traversing methods

Changed June 06, 2011 03:40PM UTC by cowboy 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 dmethvin 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: openclosed