문제

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!

도움이 되었습니까?

해결책

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/

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top