Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to sort divs according to their id using jQuery?

I have a set of divs with random ids:

<div id="container">
   <div id="2"></div>
   <div id="9"></div>
   <div id="7"></div>
   <div id="1"></div>
   <div id="4"></div>
</div>

Is there a fast way to sort them according to their id values using jQuery? Thank you.

like image 342
ababa Avatar asked Feb 28 '10 16:02

ababa


1 Answers

I'd use the tinysort plugin:

http://tinysort.sjeiti.com/

In your case it would be something like:

$("#container > div").tsort("",{attr:"id"});

like image 51
Wikser Avatar answered Sep 19 '22 13:09

Wikser