I'm trying to organize all chapters and their respective topics from a book in a html table. If I add a td for each topic (from all 22 chapters) the table will get too long. I'd like to set a button inside every chapter's td, so that I can display all topics in a tr below just by clicking it.
I thought the code below would work fine, but it didn't. Any ideas? Thanks!
var t1 = document.getElementById("t1");
function TogTop() {
if (t1.classList.contains("show") == false) {
t1.classList.add("show");
} else {
t1.classList.remove("show");
}
}
#t1 {
display: none;
}
.show {
display: block;
}
<table>
<tbody>
<tr>
<td>[1] Data Communications, Data Networking, and the Internet <button onclick="TogTop()">Topics</button></td>
<td>[2] Protocol Architecture, TCP/IP, and the Internet-Based Applications</td>
</tr>
<tr id="t1">
<td colspan="2">
<ul>
<li>1</li>
<li>2</li>
<li>3</li>
</ul>
</td>
</tr>
<tr>
<td>[3] Data Transmission</td>
<td>[4] Transmission Media</td>
</tr>
<tr>
<td>[5] Signal Encoding Techniques</td>
<td>[6] Digital Data Communication Techniques</td>
</tr>
</tbody>
</table>
.t1 { display: none;}and.show { display: block;} and<tr class="t1">`