Skip to Menu
jQuery.fn.reverse = function()
{
	return this.pushStack(this.get().reverse(), arguments);
};
var mylist;
// execute when page is ready
$(
	function()
	{
		var s = "";
		mylist = $("#mylist li");
		mylist.each(
			function()
			{
				if(s != "") s += "<br />";
				s += "- " + $(this).text();
			}
		)
		.append(" (<a href='#'>get index</a>)")
		.find("a")
		.click(
			function()
			{
				alert("#mylist li index = " + mylist.index(this.parentNode));
				return false;
			}
		);
		$("#mylist").siblings("h2").after(mylist.parent().attr("id", "mylist2").clone(false));
		$("#mylist2").append(mylist.reverse().clone());
	}
);

ul #mylist

  • One
  • Two
  • Three
  • Four

List reversed