Bug Tracker

Modify

Ticket #4446 (closed enhancement: wontfix)

Opened 5 years ago

Last modified 3 years ago

.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:
Blocking: Blocked by:

Description (last modified by dmethvin) (diff)

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

comment:1 Changed 5 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 5 years ago by brandon

  • Description modified (diff)

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

  • Keywords filter added
  • Priority changed from minor to low
  • Status changed from new to open
  • Milestone changed from 1.4 to 1.5

comment:6 Changed 3 years ago by dmethvin

  • Component changed from core to traversing

comment:7 Changed 3 years ago by gg

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

comment:8 Changed 3 years ago by addyosmani

#6966 is a duplicate of this ticket.

comment:9 Changed 3 years ago by john

  • Milestone set to 1.next

Let's consider this for 1.7.

comment:10 Changed 3 years ago by john

  • Keywords andSelf,filter,1.7-discuss added; andSelf filter removed

Nominating ticket for 1.7 discussion.

comment:11 Changed 3 years ago by dmethvin

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

comment:12 Changed 3 years ago by rwaldron

  • Description modified (diff)

+0,

comment:13 Changed 3 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 3 years ago by ajpiano

  • Description modified (diff)

-1, .andSelf should do what it says.

comment:15 Changed 3 years ago by timmywil

  • Description modified (diff)

+0, plugin

comment:16 Changed 3 years ago by danheberden

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

comment:17 Changed 3 years ago by paul.irish

  • Description modified (diff)

-1

comment:18 Changed 3 years ago by john

  • Description modified (diff)

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

comment:19 Changed 3 years ago by scott.gonzalez

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

comment:20 Changed 3 years ago by addyosmani

-1

comment:21 Changed 3 years ago by jzaefferer

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

comment:22 Changed 3 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 3 years ago by dmethvin

  • Status changed from open to closed
  • Resolution set to wontfix
  • Description modified (diff)

Please follow the  bug reporting guidlines and use  jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

View

Add a comment

Modify Ticket

Action
as closed
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.