#7411 closed feature (wontfix)
Add reverse() function to jQuery core
Reported by: | Owned by: | ajpiano | |
---|---|---|---|
Priority: | low | Milestone: | 1.5 |
Component: | core | Version: | 1.4.4rc |
Keywords: | Cc: | addyosmani, john, dmethvin, slexaxton, ajpiano | |
Blocked by: | Blocking: |
Description
Why isn't there a reverse() function in the jQuery core, to reverse the order of objects in a jQuery collection? This is a very simple thing to implement, yet I feel it should be in the core so that people can quickly get the functionality instead of having to hunt it down on the web and define their own function. Something like this should do:
jQuery.fn.reverse = Array.prototype.reverse;
Change History (8)
comment:1 Changed 12 years ago by
comment:2 Changed 12 years ago by
Cc: | addyosmani snover john dmethvin slexaxton ajpiano jitter added |
---|---|
Component: | unfiled → core |
Keywords: | needsreview added |
Priority: | undecided → low |
Status: | new → open |
I think this might indeed be useful, lets see what the others have to say
comment:3 Changed 12 years ago by
I second rwaldron's comments. This looks like it should belong in core and has been requested outside the tracker a number of times over the past few years. I see that Brandon touched upon this too last year http://forum.jquery.com/topic/jquery-reverse-a-collection-of-jquery-elements
comment:4 Changed 12 years ago by
+1 on this. It's barely any code to implement, and I've had to provide it to a lot of people who have asked over time.
comment:5 Changed 12 years ago by
The ticket seems to have 0 votes at the moment ... :)
Most jQuery operations return nodes in document order, so we'd need to document what happens if other operations are performed after a reverse.
comment:6 Changed 12 years ago by
Cc: | snover removed |
---|
comment:7 Changed 12 years ago by
Owner: | set to ajpiano |
---|---|
Status: | open → assigned |
comment:8 Changed 12 years ago by
Cc: | jitter removed |
---|---|
Keywords: | needsreview removed |
Resolution: | → wontfix |
Status: | assigned → closed |
After some discussion dmethvin, ajpiano and me came to the conclusion that adding a reverse function to the core wouldn't be of great use. Especially if you consider chaining and that most other methods would immediately restore the dom-order of the elements.
If you just need the current elements in the set in reverse order just do
//get a plain array of elements then call reverse on that $(something).get().reverse();
If you insist having this as a method on the jQuery object you can monkey patch it using something along these lines
$.fn.reverse = Array.prototype.reverse
Forgot to mention; typical use case for this function:
jQuery('div.stuffToReverse').children().reverse().each(function(){
});