jQuery UI get the sorted position of LI element in UL

Posted by PeterBZ on Stack Overflow See other posts from Stack Overflow or by PeterBZ
Published on 2010-12-30T01:31:14Z Indexed on 2010/12/30 1:54 UTC
Read the original article Hit count: 244

Filed under:
|
|

I'm using jQuery UI's sortable for my UL list. Each time the user sorts the list, I want each li element to update it's "position" attribute to it's position in the list.

<ul>
<li position="1">a</li>
<li position="2">b</li>
<li position="3">c</li>
</ul>

So when a user swaps c with a, the position will also update. I tried to use .each but it seems that javascript doesn't follow the order of how the LI elements are displayed but the order of the element's creation.

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about jquery-ui