Reputation: 13510
jQuery can return last or first child,it works ok.
But I need to get second child.
This construction (get child by index) doesn't work,when get its text:
child.parent().parent().children().get(1).text()
So, how can i find non-last and non-first child (e.g. second)?
Upvotes: 22
Views: 33512
Reputation: 2448
In one of my sites, I have:
$('#tr_' + intID).find("td").eq(3).html("Hello there!");
Essentially, this will get all the TD
elements from a table TR
with id='tr_123'
.
eq(3)
then gets the (0
-indexed!) fourth cell of that TR
, and changes its HTML contents to Hello there!
.
Upvotes: 1
Reputation: 3936
Try eq()
instead of get()
:
child.parent().parent().children().eq(1).text()
You can also do it by selector:
$("div:eq(1)")
Upvotes: 8