Bug Tracker

Opened 11 years ago

Last modified 9 years ago

#4446 closed enhancement

.andSelf(selector) — at Version 2

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

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 (2)

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)
Note: See TracTickets for help on using tickets.