How can i get the order position of Jquery sortable list?
If your elements have IDs (if they don't, pick a prefix and number them) you can use the toArray method to get the array of IDs in their current order, for example:
var idsInOrder = $(selector).sortable("toArray");
If you want to find the position of a particular one, use $.inArray(), like this:
var index = $.inArray("idToLookFor", idsInOrder);
This will return the 0-based index in the list the ID you're looking for is, or -1 if it's not found.
More generally, if you just want to get the index of an element amongst its siblings, use .index() with no parameters, like this:
$("#myElem").index();
If your sortable was for example a <ul> with sortable <li> children, calling this on an <li> would also get it's 0-based index, within it's siblings.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With