Opened 14 years ago
Closed 12 years ago
#4446 closed enhancement (wontfix)
.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 (last modified by )
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 (23)
comment:1 Changed 14 years ago by
comment:2 Changed 14 years ago by
Description: | modified (diff) |
---|
comment:3 Changed 13 years ago by
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 13 years ago by
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 13 years ago by
Keywords: | filter added |
---|---|
Milestone: | 1.4 → 1.5 |
Priority: | minor → low |
Status: | new → open |
comment:6 Changed 13 years ago by
Component: | core → traversing |
---|
comment:7 Changed 12 years ago by
I've submitted a pull request which implements this: https://github.com/jquery/jquery/pull/203
comment:10 Changed 12 years ago by
Keywords: | 1.7-discuss added |
---|
Nominating ticket for 1.7 discussion.
comment:11 Changed 12 years ago by
+1, I like the feature but maybe we can find something better than .andSelf()
to describe it?
comment:13 Changed 12 years ago by
-1, I'd like these kind of helpers to be added into an official plugin, not be put in core.
comment:14 Changed 12 years ago by
Description: | modified (diff) |
---|
-1, .andSelf should do what it says.
comment:16 Changed 12 years ago by
+1, Seems reasonable since most other stack addition functions take a selector
comment:18 Changed 12 years ago by
Description: | modified (diff) |
---|
-1, I don't really agree with the API change.
comment:21 Changed 12 years ago by
+1, useful, and provides consistent optional filtering for traversing methods
comment:22 Changed 12 years ago by
+1, Doing this would not only be cool, it would make #4596 a non-issue (see my comment there)
comment:23 Changed 12 years ago by
Description: | modified (diff) |
---|---|
Resolution: | → wontfix |
Status: | open → closed |
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.