Reputation: 2441
I am currently using the Sortable Widget to swap divs in my page but the problem is it doesn't arrange the value if the div / li when sorting it,
EX:
<ul class="sortable">
<li id="1">a</li>
<li id="2">b</li>
<li id="3">c</li>
<li id="4">d</li>
<li id="5">e</li>
</ul>
when i move 5 to the top the arrangement should arrange all of the id / name from
5 = e, 1 = a, 2 = b, 3 = c, 4 = d
to
1 = e, 2 = a, 3 = b, 4 = c, 5 = d
once again, how will i be able to achieve this using jquery?
Upvotes: 0
Views: 65
Reputation: 144659
You can reset the IDs using .prop()
method on update
event:
// ...
update: function() {
$('.sortable li').prop('id', function(i) { return ++i; });
}
However, I would recommend using data-*
attributes instead of using id
s.
Upvotes: 1