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. Required fields are marked *