JS implements the method of adding a new cell to a table row

  • 2020-05-24 05:11:24
  • OfStack

This article demonstrates how the JS implementation adds a new cell to a table row. Share with you for your reference. The details are as follows:

The JS code below inserts a new cell into the row in the table that specifies id


<!DOCTYPE html>
<html>
<head>
<script>
function insCell()
{
var x=document.getElementById('tr1').insertCell(0);
x.innerHTML="The famous";
}
</script>
</head>
<body>
<table border="1">
<tr id="tr1">
<td>Peter</td>
<td>Griffin</td>
</tr>
</table>
<br>
<input type="button" onclick="insCell()" value="Insert cell">
</body>
</html>

I hope this article has been helpful to your javascript programming.


Related articles: