i have a href link under my table and i want to be able to manipulate table rows by clicking on that link but i cant get them !
here is my html
<div>
<div> <a href="#remove" class="removelink" > remove </a> </div>
<table>
<tr> <td></td> </tr>
</table>
</div>
i want to do something like:
$('.removelink').click(function(){
$(this).parent().siblings('table tr:last').remove();
})
i can get to the table by
$(this).parent().siblings('table')
but i cant get rows by something like
$(this).parent().siblings('table tr')
You can use
findto get to thetrfrom thetable:Here’s a working example. If your HTML structure is always exactly as you’ve shown, you could use
next()instead ofsiblings('table')for slightly shorter code.The problem with your current code is that
siblings('table tr')will look for a sibling of thedivwhich is atr, and there are none!