NOTE: As of July 12, 2009, this blog has been discontinued and replaced by the new Thought Delimited blog. All of the entries in this blog can be found there, along with new posts.
Using jQuery Manipulation Functions (Append, Prepend, After, Before) To Reorder Items
- Select all of the items that had the trait and store them in an array
- Resort the contents of the array into a new array.
- Delete the selected items from the list (so as not to replicate them)
- Loop through the new array and add the items back into the list using the jQuery prepend() function to put them at the top of the list.
When I ran my first test of my code, I left out the deletion step so I could compare the original item order with the new item order, figuring I would have duplicates of the selected items.
However, I was surprised to discover that prepend() removed the original instances of the selected list items, leaving only the prepended copies. Essentially, it ended up moving the items rather than duplicating them.
There's nothing on the official documentation page that says that if you're prepending an item to a collection that already contains an instance of that item that it will remove the original item for you, but that's apparently what it's programmed to do.
I ran a quick test of some of the other related Manipulation functions (append(),after(),before()), and they all seem to behave that way as well.
Thought it was worth sharing. Certainly makes my reordering task a bit easier.


If you put them somewhere .. that's where they'll go.
Similarly if you add an attribute (e.g. toggle a class) on those items, the class will be applied to the items .. not a copy of the items in memory .. otherwise you would have to "re-add" the item to the DOM once you had manipulated it.
(btw your captcha is slightly unreadable .. got it wrong the first time = poor usability)
Features jQuery
* Move the tree DOM, including support XPath as a plug;
* Event;
* Visual effects;
* AJAX-supplements;
* JavaScript-plugins.
You can find many applications for your sites on a site http://www.queentorrent.com and free to download.
http://novablog.co.cc http://venomancer.co.cc http://fxtech.wordpress.com http://smot.blogsome.com http://phonemark.blogspot.com http://forexcontest.co.cc http://forexjournal.co.cc http://forexweblog.co.cc http://fxsignal.co.cc http://nextstar.co.cc http://blogsign.co.cc http://trendmark.co.cc http://hotspeak.co.cc