Q:

jQuery - Button to arrange elements by id in descending order

I have a collection of divs with id of 0, 1, 2, 3, n. They are generated in php in ascending order. I want to make a button to re-arrange them so they display in descending order using jquery. I have absolutely no clue how to do this. Can anyone refer me to an article or something?
Code:
<span>
    <div id="0">...</div>
    <div id="1">...</div>
    <div id="2">...</div>
    <div id="3">...</div>
    <div id="4">...</div>
    ...
</span>

I want a button to make it:
<span>
....
    <div id="4">...</div>
    <div id="3">...</div>
    <div id="2">...</div>
    <div id="1">...</div>
    <div id="0">...</div>
</span>

A:

try this
$('span div').each(function() {
    $(this).insertBefore('span div:first');
});

http://jsfiddle.net/BS4g3/

