Javascript examples for DOM HTML Element:TableData
You can create a <td> element by using the document.createElement() method:
<!DOCTYPE html> <html> <head> <style> table, th, td { border: 1px solid black; } </style>//w ww . j a va2s . c om </head> <body> <table id="myTable"> <tr id="myTr"> </tr> </table> <button onclick="myFunction()">create a TD element</button> <script> function myFunction() { var x = document.createElement("TD"); var t = document.createTextNode("new cell"); x.appendChild(t); document.getElementById("myTr").appendChild(x); } </script> </body> </html>