<!DOCTYPE html>
<html>
<head>
<style>
table, td {
border: 1px solid black;
}
</style>
</head>
<body>
<table id="myTable">
</table>
<p>Click the button to create a TR and a TD element.</p>
<button onclick="myFunction()">Try it</button>
<script>
function myFunction() {
var x = document.createElement("TR");
x.setAttribute("id", "myTr");
document.getElementById("myTable").appendChild(x);
var y = document.createElement("TD");
var t = document.createTextNode("new cell");
y.appendChild(t);
document.getElementById("myTr").appendChild(y);
}
</script>
</body>
</html>