$(document.ready(function() {
var laterbox = document.getElementById('laterbox');
var tabl = document.createElement('table');
var trh = document.createElement('tr');
var trd = document.createElement('tr');
var txt = document.createTextNode('book_id');
var tr1 = document.createElement('th');
tr1.appendChild(txt);
trh.appendChild(tr1);
tabl.appendChild(trh);
tabl.appendChild(trd);
laterbox.appendChild(tabl);
}));
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="laterbox">
<table>
<tr>
<th>aa</th>
<th>bb</th>
</tr>
<tr>
</tr>
</table>
</div>
But the second table does't display, I don't know why. I tried many times but could not find the error. You can see the output here: https://codepen.io/sandesh_bafna8/pen/BwQZGv
tabl1,tr1and stuff like that do in a bigger codebase is a real pain and leads to more time spent figuring it out than the time it would take to typetableToInsertortableRow. :)