jQuery > Selectors

nth-child(n) - Nth child in jQuery

How to select a specific child of the parent element in jQuery?


To select a specific child of the parent element, nth child selector can be used. 

<script language="javascript" type="text/javascript">
$("#div2 p:nth-child(2)").css("background", "red");
</script>

Above code snippet will select the 2nd paragraph (p) element that is inside the div element whose id is “div2” and will change the background color as red. 

 Views: 7954 | Post Order: 17



Write for us






Hosting Recommendations