4

I have a CMS and in my CMS I need to sort my menu by jquery sortable!

What is the result of sorting, I mean when I drag and drop an element by sortable what is the result of sorting? does jquery sortable give me a number of index?

for example:

when I drag an Item that is at the first in the menu, and put it at the end of the menu how to get index of the item at it's new position?

1 Answer 1

6

You can handle the event sortstop (which can be done via the option stop), at this time the items have already had new order, you can access to the ui.item to get the dropped item and use .index() method to know its index in the collection of items (having the same parent):

$('ul').sortable({
  stop: function(e,ui){
    //show the index
    alert(ui.item.index());
  }
});

Demo.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.