Toggle table row siblings
- by kuswantin
I have a table structured like this:
<table>
<tr id="id1" class="parent"></tr>
<tr class="id1"></tr>
<tr class="id1"></tr>
<tr class="id1"></tr>
<tr class="id1"></tr>
<tr id="id2" class="parent"></tr>
<tr class="id2"></tr>
<tr class="id2"></tr>
<tr class="id2"></tr>
<tr class="id2"></tr>
.....etc
</table>
As you can see child classes are coresponding to their parent id. Now I want to toggle all the rows which have class names equal to their parent row id whenever parent row is clicked.
I have tried this, perhaps stupid try:) and can't seem to get this working:
$('tr.parent').click(function() {
//alert('yay');
var tog = $(this).attr('id');
$(this).siblings().hasClass(tog).slideToggle();
return false;
});
Thanks.