ahren ahren - 3 years ago 165
Javascript Question

Get position of selected elements, not index of element in DOM

<h3>Heading one</h3>
<h3>Heading two</h3>
<h4>heading caption</h4>
<h3>Heading three</h3>

I want to get the position of the element within the jQuery selection, rather than it's index in the DOM.

At the moment, if I
I'll get '3' - I want '2'.


Answer Source

Pass your index() a selector:

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download