Bug Tracker

Opened 11 years ago

Closed 8 years ago

#4446 closed enhancement (wontfix)


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 (last modified by dmethvin)

Why not andSelf() function to have a selector param. Here is a particular example


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; }

Change History (23)

comment:1 Changed 11 years ago by dmethvin

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.

comment:2 Changed 10 years ago by brandon

Description: modified (diff)

comment:3 Changed 9 years ago by scottsb

I would find this feature very useful. It seems like an appropriate change to to bring andSelf() in line with the other traversal methods.

comment:4 Changed 9 years ago by boushley

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.

comment:5 Changed 9 years ago by SlexAxton

Keywords: filter added
Milestone: 1.41.5
Priority: minorlow
Status: newopen

comment:6 Changed 9 years ago by dmethvin

Component: coretraversing

comment:7 Changed 9 years ago by gg

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

comment:8 Changed 9 years ago by addyosmani

#6966 is a duplicate of this ticket.

comment:9 Changed 9 years ago by john

Milestone: 1.next

Let's consider this for 1.7.

comment:10 Changed 8 years ago by john

Keywords: 1.7-discuss added

Nominating ticket for 1.7 discussion.

comment:11 Changed 8 years ago by dmethvin

+1, I like the feature but maybe we can find something better than .andSelf() to describe it?

comment:12 Changed 8 years ago by Rick Waldron

Description: modified (diff)


comment:13 Changed 8 years ago by jaubourg

-1, I'd like these kind of helpers to be added into an official plugin, not be put in core.

comment:14 Changed 8 years ago by ajpiano

Description: modified (diff)

-1, .andSelf should do what it says.

comment:15 Changed 8 years ago by timmywil

Description: modified (diff)

+0, plugin

comment:16 Changed 8 years ago by danheberden

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

comment:17 Changed 8 years ago by paul.irish

Description: modified (diff)


comment:18 Changed 8 years ago by john

Description: modified (diff)

-1, I don't really agree with the API change.

comment:19 Changed 8 years ago by scottgonzalez

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

comment:20 Changed 8 years ago by addyosmani


comment:21 Changed 8 years ago by jzaefferer

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

comment:22 Changed 8 years ago by cowboy

+1, Doing this would not only be cool, it would make #4596 a non-issue (see my comment there)

comment:23 Changed 8 years ago by dmethvin

Description: modified (diff)
Resolution: wontfix
Status: openclosed
Note: See TracTickets for help on using tickets.