jQuery – Get a childs relative position

When processing sortables etc. Its handy to be able to get the index of individual items. Heres how you find the position of an li within a list:

var position = $item.parent().find('> li').index($item) + 1;

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.