views:

239

answers:

1

Hi.

I have a div containing several other divs containing an image. It looks smth like this

<div id="parentHldr">
 <div class="imgHldr"><img src="foo/bar.png" id="1"></div>
 <div class="imgHldr"><img src="foo/bar.png" id="2"></div>
 <div class="imgHldr"><img src="foo/bar.png" id="3"></div>
 <div class="imgHldr active"<img src="foo/bar.png" id="4"></div>
 <div class="imgHldr"><img src="foo/bar.png" id="5"></div>
 <div class="imgHldr"><img src="foo/bar.png" id="6"></div>
</div>

I want to know the position of div that has class active. I get total number of children elements with this thing

$('#parentHldr').children().length

So i presume, there should be a way of finding the positional number of that div somehow...

ok, i've practically found the solution. Now its a bit more complicated. I need to get index of a DIV w/ class imgHldr containing img with id 5 inside the parent DIV w/ class parentHldr. Is this possible??))

+2  A: 

Use index():

$("#parentHldr > div").index($("#parentHldr > div.active"));
Martin
Yep, that's it. Thanks a lot, forgot to tag this as noob-question ;) GOD, I love stackoverflow!!
dr3w