Reputation: 13614
I want to insert dynamically created table to the div element after button "click me!" pressed.
Here it the code:
<body>
<button onclick="CreatTable()">click me!</button>
<div id="ShowDataID"></div>
<script type="text/javascript">
var data = ['First Name', 'Last Name', 'Email'];
function CreatTable() {
var table = document.createElement('table');
//some logic to fill table
document.getElementById('ShowDataID').innerHTML = table;
}
</script>
</body>
But after I press "click me!" button table not displayed.
Why table not displayed what I am missing here?
Upvotes: 0
Views: 59
Reputation: 77482
#1
function CreatTable() {
var table = document.createElement('table');
document.getElementById('ShowDataID').appendChild(table);
}
#2
function CreatTable() {
var _tmp = document.createElement('div'),
table = document.createElement('table');
_tmp.appendChild(table);
document.getElementById('ShowDataID').innerHTML = _tmp.innerHTML;
}
Upvotes: 2