In This Javascript Tutorial we will See How To Remove HTML Table On Button Click
In JS And Netbeans Editor .
Subscribe : https://www.youtube.com/channel/UCS3W5vFugqi6QcsoAIHcMpw
Project Source Code:
<!DOCTYPE html>
<html>
<head>
<title>Remove HTML Table Selected Row</title>
<meta charset="windows-1252">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<style>
td:last-child{background-color: #F00;color:#FFF;cursor: pointer;
font-weight: bold;text-decoration: underline}
</style>
</head>
<body>
<table id="table" border="1">
<tr>
<th>First Name</th>
<th>Last Name</th>
<th>Age</th>
<th>Delete</th>
</tr>
<tr>
<td>FN1</td>
<td>LN1</td>
<td>10</td>
<td>remove</td>
</tr>
<tr>
<td>FN2</td>
<td>LN2</td>
<td>20</td>
<td>remove</td>
</tr>
<tr>
<td>FN3</td>
<td>LN3</td>
<td>30</td>
<td>remove</td>
</tr>
<tr>
<td>FN4</td>
<td>LN4</td>
<td>40</td>
<td>remove</td>
</tr>
<tr>
<td>FN5</td>
<td>LN5</td>
<td>50</td>
<td>remove</td>
</tr>
</table>
<script>
var index, table = document.getElementById('table');
for(var i = 1; i < table.rows.length; i++)
{
table.rows[i].cells[3].onclick = function()
{
var c = confirm("do you want to delete this row");
if(c === true)
{
index = this.parentElement.rowIndex;
table.deleteRow(index);
}
//console.log(index);
};
}
</script>
</body>
</html>
#javascript #js