Find nth-child Inside a Div using Javascript
by Sasikumar[ Edit ] 2014-05-29 17:34:15
To find nth-child of a particular class inside a div use the following mwthod,
<div id="mainContainer">
<div class="innerDiv" id="1"></div>
<div class="innerDiv" id="2"></div>
<div class="innerDiv" id="3"></div>
<div class="innerDiv" id="4"></div>
</div>
<script type="text/javascript"> alert( $("#mainContainer > .innerDiv:nth-child(3n)").attr('id') ); </script>
Output:
This will alert you "3" as the "id" of 3rd child div is 3