Move this topic
[jQuery] Reverse a collection of jQuery elements.
in Using jQuery
•
13 years ago
I need to reverse the collection jQuery returns when I use
$("#some_selector").parents("li");
in order to build a path.
Is this doable? It'd be nice if jQuery had a reverse() method.
Replies(3)
$.fn.reverse = [].reverse;
$('#some_selector').parents('li').reverse();
:)
--
Brandon Aaron
Leave a comment on brandon_aaron's reply
<html><body>
var temp = new Array();
var objects = <tt>$("#some_selector").parents("li");</tt>
for(var i = 0; i < objects.size(); i++)
{
temp[(objects.size()-1) - i] = objects.eq(i);
}
pretty sure that after that runs the temp array will contain your objects in reverse order. please correct me if i'm wrong here, trying to write this at the last minute before leaving work :)
cheers
Michael Lawson
Development Lead, Global Solutions, ibm.com
Phone: 1-276-206-8393
E-mail: mjlawson@us.ibm.com
'Examine my teachings critically, as a gold assayer would test gold. If you find they make sense, conform to your experience, and don't harm yourself or others, only then should you accept them.'
<img width="16" height="16" src="cid:1__=08BBFF50DFEBA8AB8f9e8a93df938@us.ibm.com" border="0" alt="Inactive hide details for simshaun ---05/27/2009 05:51:32 PM---I need to reverse the collection jQuery returns when I use"><font color="#424282">simshaun ---05/27/2009 05:51:32 PM---I need to reverse the collection jQuery returns when I use</font>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr valign="top"><td width="1%"><img width="96" height="1" src="cid:2__=08BBFF50DFEBA8AB8f9e8a93df938@us.ibm.com" border="0" alt="">
<font size="2" color="#5F5F5F">From:</font></td><td width="100%"><img width="1" height="1" src="cid:2__=08BBFF50DFEBA8AB8f9e8a93df938@us.ibm.com" border="0" alt="">
<font size="2">simshaun <simshaun@gmail.com></font></td></tr>
<tr valign="top"><td width="1%"><img width="96" height="1" src="cid:2__=08BBFF50DFEBA8AB8f9e8a93df938@us.ibm.com" border="0" alt="">
<font size="2" color="#5F5F5F">To:</font></td><td width="100%"><img width="1" height="1" src="cid:2__=08BBFF50DFEBA8AB8f9e8a93df938@us.ibm.com" border="0" alt="">
<font size="2">"jQuery (English)" <jquery-en@googlegroups.com></font></td></tr>
<tr valign="top"><td width="1%"><img width="96" height="1" src="cid:2__=08BBFF50DFEBA8AB8f9e8a93df938@us.ibm.com" border="0" alt="">
<font size="2" color="#5F5F5F">Date:</font></td><td width="100%"><img width="1" height="1" src="cid:2__=08BBFF50DFEBA8AB8f9e8a93df938@us.ibm.com" border="0" alt="">
<font size="2">05/27/2009 05:51 PM</font></td></tr>
<tr valign="top"><td width="1%"><img width="96" height="1" src="cid:2__=08BBFF50DFEBA8AB8f9e8a93df938@us.ibm.com" border="0" alt="">
<font size="2" color="#5F5F5F">Subject:</font></td><td width="100%"><img width="1" height="1" src="cid:2__=08BBFF50DFEBA8AB8f9e8a93df938@us.ibm.com" border="0" alt="">
<font size="2">[jQuery] Reverse a collection of jQuery elements.</font></td></tr>
</table>
<hr width="100%" size="2" align="left" noshade style="color:#8091A5; ">
<tt>
I need to reverse the collection jQuery returns when I use
$("#some_selector").parents("li");
in order to build a path.
Is this doable? It'd be nice if jQuery had a reverse() method.
</tt>
</body></html>
Attachments
Leave a comment on mjlawson1's reply
<html><body>
hehe what Brandon said!
cheers
Michael Lawson
Development Lead, Global Solutions, ibm.com
Phone: 1-276-206-8393
E-mail: mjlawson@us.ibm.com
'Examine my teachings critically, as a gold assayer would test gold. If you find they make sense, conform to your experience, and don't harm yourself or others, only then should you accept them.'
<img width="16" height="16" src="cid:1__=08BBFF50DFEBF6348f9e8a93df938@us.ibm.com" border="0" alt="Inactive hide details for Brandon Aaron ---05/27/2009 05:54:11 PM---$.fn.reverse = [].reverse;"><font color="#424282">Brandon Aaron ---05/27/2009 05:54:11 PM---$.fn.reverse = [].reverse;</font>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr valign="top"><td width="1%"><img width="96" height="1" src="cid:2__=08BBFF50DFEBF6348f9e8a93df938@us.ibm.com" border="0" alt="">
<font size="2" color="#5F5F5F">From:</font></td><td width="100%"><img width="1" height="1" src="cid:2__=08BBFF50DFEBF6348f9e8a93df938@us.ibm.com" border="0" alt="">
<font size="2">Brandon Aaron <brandon.aaron@gmail.com></font></td></tr>
<tr valign="top"><td width="1%"><img width="96" height="1" src="cid:2__=08BBFF50DFEBF6348f9e8a93df938@us.ibm.com" border="0" alt="">
<font size="2" color="#5F5F5F">To:</font></td><td width="100%"><img width="1" height="1" src="cid:2__=08BBFF50DFEBF6348f9e8a93df938@us.ibm.com" border="0" alt="">
<font size="2">jquery-en@googlegroups.com</font></td></tr>
<tr valign="top"><td width="1%"><img width="96" height="1" src="cid:2__=08BBFF50DFEBF6348f9e8a93df938@us.ibm.com" border="0" alt="">
<font size="2" color="#5F5F5F">Date:</font></td><td width="100%"><img width="1" height="1" src="cid:2__=08BBFF50DFEBF6348f9e8a93df938@us.ibm.com" border="0" alt="">
<font size="2">05/27/2009 05:54 PM</font></td></tr>
<tr valign="top"><td width="1%"><img width="96" height="1" src="cid:2__=08BBFF50DFEBF6348f9e8a93df938@us.ibm.com" border="0" alt="">
<font size="2" color="#5F5F5F">Subject:</font></td><td width="100%"><img width="1" height="1" src="cid:2__=08BBFF50DFEBF6348f9e8a93df938@us.ibm.com" border="0" alt="">
<font size="2">[jQuery] Re: Reverse a collection of jQuery elements.</font></td></tr>
</table>
<hr width="100%" size="2" align="left" noshade style="color:#8091A5; ">
<tt>
$.fn.reverse = [].reverse;
$('#some_selector').parents('li').reverse();
:)
--
Brandon Aaron
Attachments
Leave a comment on mjlawson1's reply
Change topic type
Link this topic
Provide the permalink of a topic that is related to this topic
Reply to shaun123's discussion