Getting the 2nd child element

Written by Leif Stenfeldt. Posted in Javascript, Programmering, Tips

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();

1000 views

Tags:

Leave a comment