Getting the 2nd child element

html, jquery, jquery-selectors

Solution

A number of ways to do this one. I'm going to assume the toplevel div has an id of 'top'. This is probably the best one:

$('#top > :nth-child(2)').whatever();

or

$('#top').children(':first-child').next().whatever();

or if you know for a fact there are at least 2 children

$($('#top').children()[1]).whatever();

Problem

I am still new in jquery and I have this code ``` <div> abcsdf <div> first child</div> <div> second child</div> </div> ``` I wanted to get the second child, they are dynamically populated using append and I don't know how to get it. I wanted to display `$('the second element inner html here').dialog() etc..` Hoping someone can help me. Thanks

Original source

Related problems