I can't delete the rows that are selected. I want to delete the rows checked with checkbox. But I can't access the table rows and check whether the checkbox is checked. What should I do?
Code:
<div class="container">
<div class="tab tab-1">
<table id="table" border="1">
<tr>
<th></th>
<th>First Name</th>
<th>Last Name</th>
<th>Age</th>
<th>edit</th>
</tr>
<tr>
<td><input type="checkbox" id="select"></td>
<td>A1</td>
<td>B1</td>
<td>10</td>
<td><input type="button" value="edit" id="edit"></td>
</tr>
<tr>
<td><input type="checkbox" id="select"></td>
<td>A3</td>
<td>B3</td>
<td>30</td>
<td><input type="button" value="edit" id="edit"></td>
</tr>
<tr>
<td><input type="checkbox" id="select" class="select"></td>
<td>A2</td>
<td>B2</td>
<td>20</td>
<td><input type="button" value="edit" id="edit"></td>
</tr>
</table>
</div>
<button onclick="deleteRow();">Remove</button>
<script>
function deleteRow() {
var table = document.getElementById("table");
var rowCount = table.rows.length;
console.log("rowcount : " + rowCount);
for (var i = 1; i < rowCount; i++) {
var c = table.rows[i].cells[0].childNodes;
console.log(c);
if (c.checked == 1) {
console.log("i :" + i);
table.deleteRow(i);
}
}
}.
</script>