Say I have a string like this:
var tablestring = "<table><tr><td>Test</td></tr></table>";
Is it possible to populate a table DOM object doing something like this:
var Test = document.createElement("TABLE");
Test.value = tablestring;
Yes it is. Using .innerHTML you can assign html to a dom element. Please see the snippet below:
function addTable(){
var tablestring = "<table><tr><td>Test</td></tr></table>";
var container = document.getElementById('container');
container.innerHTML = tablestring;
}
<button onclick="addTable()"> Add table </button>
<div id="container"></div>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With