Possible Duplicate:
jQuery: Sort div's according to content of different sub divs
Is it possible to sort the contents of div
<div id="sort">
<div id="something">A2</div>
<div id="something">A1</div>
<div id="something">A4</div>
<div id="something">A3</div>
</div>
sorted to:
<div id="sort">
<div id="something">A1</div>
<div id="something">A2</div>
<div id="something">A3</div>
<div id="something">A4</div>
</div>
Anything like this????
$('#sort').sort();
What about this?
var mylist = $('#sort');
var listitems = mylist.children('div').get();
listitems.sort(function(a, b) {
return $(a).text().toUpperCase().localeCompare($(b).text().toUpperCase());
});
$.each(listitems, function(index, item) {
mylist.append(item);
});
Pulled from: http://www.onemoretake.com/2009/02/25/sorting-elements-with-jquery/
And This: How may I sort a list alphabetically using jQuery?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With