I need to find the index of element with class "span":
<div>
<div>
<div class="sd">
<h2> H2 TEXT </h2>
<span> SPAN </span>
<span class="span"> SPAN </span>
</div>
</div>
</div>
So i did:
var q = $('div > div > div.sd').find('.span').index();
alert(q)
This alerts "2" but the class is the first and only so it should alert "1". Is this because Jquery looks for the tag and not the class? I googled a lot and searched on stack but all examples include a click event which I don't want.
Live example: http://jsfiddle.net/jL7dsv5y/
0?index, and it will find its position within that collection.