Miyerkules, Oktubre 7, 2015

How to Add Tables in a Div Dynamically in Javascript

Hi All!

Here's how to add Tables dynamically in your page. First is to make a DIV for your tables and button for adding tables.

<div id="tables">
</div>

<button onClick="AddTab();">Add Table</button>

Then write below code in your script.

<script type="text/javascript">
function addTab(val) {
var table = document.createElement('table');
var row = table.insertRow(0);
var cell1 = row.insertCell(0);
cell1.innerHTML = 'Hi';

var div = document.getElementById('tables');
    div.appendChild(table);
</script>

And That's it.

Goodluck.

Walang komento:

Mag-post ng isang Komento