Friday, 15 May 2015

javascript - Insert table to div element -



javascript - Insert table to div element -

i want insert dynamically created table div element after button "click me!" pressed.

here code:

<body> <button onclick="creattable()">click me!</button> <div id="showdataid"></div> <script type="text/javascript"> var info = ['first name', 'last name', 'email']; function creattable() { var table = document.createelement('table'); //some logic fill table document.getelementbyid('showdataid').innerhtml = table; } </script> </body>

but after press "click me!" button table not displayed.

why table not displayed missing here?

#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; }

http://jsbin.com/soceca/1/

javascript

No comments:

Post a Comment