Bug Tracker

Opened 11 years ago

Last modified 9 years ago

#4446 closed enhancement

.andSelf(selector) — at Version 12

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

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

Change History (12)

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 11 years ago by brandon

Description: modified (diff)

comment:3 Changed 10 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 10 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 10 years ago by SlexAxton

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

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

Keywords: 1.7-discuss added

Nominating ticket for 1.7 discussion.

comment:11 Changed 9 years ago by dmethvin

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

comment:12 Changed 9 years ago by Rick Waldron

Description: modified (diff)

+0,

Note: See TracTickets for help on using tickets.