I’m pointing at the first div inside my table’s td as you can see in the jQuery code below.
$('table tr td div').css("position", "relative");
But I’ve got some problems with that so I’ve tried this:
$('table tr td').parents('div:first').css({position:'relative'});
But this one doesn’t work fine either. What is wrong with my code?
My HTML structure is:
<table>
<tr>
<td><!-- all id for the div and image inside the td are dynamic -->
<div><!-- Need to access this div -->
<!-- content --->
</div>
</td>
</tr>
</table>
.parents()find all parent of your selection. what you want is a child.This will do the trick for you 🙂
You also might want to select only exact descendants, in that case you can use: