ItHurtsWhenIThink
Technical User
I want to hide a set of table rows and have the ability to open a set as well. I am working with a dynamic table. So the rows I want to hide or open will have the same "id". I want all the rows with the same id to close or open. The problem I have right now, is that only the first row will show up when I open the row even though there may be several rows with the same id. So in the code below list two will only show items: 1,2,3 but not item 4-12.
Code:
Code:
JavaScript:
<script language="JavaScript">
function toggle_visibility(id) {
var list = document.getElementsByClassName("alist");
for (var i = 0; i < list.length; i++) {
list[i].style.display = 'none';
}
var e = document.getElementById(id);
if(e.style.display == 'table-row') {
e.style.display = 'none';
} else {
e.style.display = 'table-row';
}
}
</script>
HTML:
<table>
<tr>
<td>
<a href="#" onclick="toggle_visibility('1');"><p>List One</p></a>
</td>
</tr>
<tr id="1" class="alist" style="display:none;">
<td>
<ul>
<li>Item One</li>
<li>Item Two</li>
<li>Item Three</li>
</ul>
</td>
</tr>
<tr>
<td>
<a href="#" onclick="toggle_visibility('2');"><p>List Two</p></a>
</td>
</tr>
<tr id="2" class="alist" style="display:none;">
<td>
<ul>
<li>Item 1</li>
<li>Item 2</li>
<li>Item 3</li>
</ul>
</td>
</tr>
<tr id="2" class="alist" style="display:none;">
<td>
<ul>
<li>Item 4</li>
<li>Item 5</li>
<li>Item 6</li>
</ul>
</td>
</tr>
<tr id="2" class="alist" style="display:none;">
<td>
<ul>
<li>Item 7</li>
<li>Item 8</li>
<li>Item 9</li>
</ul>
</td>
</tr>
<tr id="2" class="alist" style="display:none;">
<td>
<ul>
<li>Item 10</li>
<li>Item 11</li>
<li>Item 12</li>
</ul>
</td>
</tr>
</table>