Determine what number li element a div is in

Say I have:

    <div id="test"></div>

Is there a way to tell from the div tag what number li tag it’s in?

I.e. in the div there is a javascript function that returns 2 since it’s inside the second li element.

I realise I could go:

  • get parent ul
  • check each li child until the div is found.

Is there a more elegant way to do this?

Source: jquery

Leave a Reply

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