I`d like the tablerow to disappear when I uncheck the checkbox. It must be only JavaScript based (exercise for school).
The creating of the checkbox works, but i cannot style the display to "none"
There are more TR's but i've deleted most of them since it gives no added value to solving the code below.
// Get parent of checkbox
var searchTr = document.querySelectorAll("#searchTable tr");
// add checkbox to parent
for (i = 1; i < searchTr.length; i++) {
var chkbox = document.createElement("input");
chkbox.type = "checkbox";
chkbox.setAttribute("class", "chkbox");
searchTr[i].appendChild(chkbox);
chkbox.checked = true;
chkbox.addEventListener("change", hideMe);
function hideMe() {
searchTr[i].style.display = "none";
}
}
<table id="searchTable" class="table table-striped table-bordered" cellspacing="0" width="100%">
<thead>
<tr>
<th class="th-sm">Name
</th>
<th class="th-sm">Position
</th>
<th class="th-sm">Office
</th>
<th class="th-sm">Age
</th>
<th class="th-sm">Start date
</th>
<th class="th-sm">Salary
</th>
</tr>
</thead>
<tbody>
<tr>
<td>Tiger Nixon</td>
<td>System Architect</td>
<td>Edinburgh</td>
<td>61</td>
<td>2011/04/25</td>
<td>$320,800</td>
</tr>
<tr>
<td>Garrett Winters</td>
<td>Accountant</td>
<td>Tokyo</td>
<td>63</td>
<td>2011/07/25</td>
<td>$170,750</td>
</tr>
</tbody>
</table>