help me figure out how to set an event on the parent element (<tr>)
I can’t find the error in the condition
<script type="text/javascript">
$('table tbody tr').each(function(){
$(this).find('a:first').click(function(){
if($(this).parents().get(1).tagName == 'TR') {
$(this).parents().get(1).find('tr').css('background', 'red'); //What's wrong?
}
});
</script>
<table>
<tbody>
<tr>
<td><a href="#">text</a></td>
<td>text</td>
</tr>
</tbody>
</table>
Unfortunately, the formatting, I don’t see any more special tag
hey you are missing closing
});foreachstatement. Here is the correct version of your codeWorking Example
EDIT: you can shorten above code very easily like assigning a class to anchor tag.