Question

I want to sort elements by position in the page. Meaning if I have an object:

$obj = $('#div1, #div2, #div3');

But my markup is like:

<div id="div3"></div>
<div id="div1"></div>
<div id="div2"></div>

How would I sort $obj to be $('#div3, #div1, #div2');

Thanks!

Was it helpful?

Solution

ok if they start with a same prefix you can do something like this

$obj = $('[id^=div]'); 

here is the fiddle: http://jsfiddle.net/wytXQ/

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top