Toggle table row siblings
Posted
by kuswantin
on Stack Overflow
See other posts from Stack Overflow
or by kuswantin
Published on 2010-03-11T21:14:49Z
Indexed on
2010/03/11
21:19 UTC
Read the original article
Hit count: 220
jQuery
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.
© Stack Overflow or respective owner