I have an existing nested HTML table with code shown below that I am trying to rebuild only using JS. I am able to do this if the table were to be flat but I am confused on how to rebuild this example HTML table I gave with only using JS. My main issue here is in the JS code if you see from the HTML example code I have heading A which I am able to do in the JS code but the part I am struggling with is the portion of the table i called heading B and the corresponding input for heading B.
Here is my existing table code that I am trying to figure out how to create via only JS JsFiddle code here
<table id="example" class="table table-striped">
<thead>
<tr>
<th>HEADING A </th>
<th>HEADING A</th>
<th>HEADING A</th>
<th>HEADING A</th>
</tr>
</thead>
<tbody>
<tr>
<td >INPUT 1.A</td>
<td >INPUT 1.A</td>
<td>INPUT 1.A</td>
<td>
<table id="example1" class="table table-nostriped">
<th>HEADING B</th>
<th>HEADING B</th>
<th>HEADING B</th>
<tr>
<td>INPUT 1.B</td>
<td>INPUT 1.B</td>
<td>INPUT 1.B</td>
</tr>
<tr>
<td>INPUT 1.B</td>
<td>INPUT 1.B</td>
<td>INPUT 1.B</td>
</tr>
<tr>
<td>INPUT 1.B</td>
<td>INPUT 1.B</td>
<td>INPUT 1.B</td>
</tr>
</table>
</td>
</tr>
<!-- Second table entry here -->
<tr>
<td >INPUT 2.A</td>
<td >INPUT 2.A</td>
<td>INPUT 2.A</td>
<td>
<table id="example1" class="table table-nostriped">
<th>HEADING B</th>
<th>HEADING B</th>
<th>HEADING B</th>
<tr>
<td>INPUT 1.B</td>
<td>INPUT 1.B</td>
<td>INPUT 1.B</td>
</tr>
<tr>
<td>INPUT 1.B</td>
<td>INPUT 1.B</td>
<td>INPUT 1.B</td>
</tr>
<tr>
<td>INPUT 1.B</td>
<td>INPUT 1.B</td>
<td>INPUT 1.B</td>
</tr>
</table>
</td>
</tr>
</tbody>
</table>
I am able to create the table if it were flat but I am having a bit of trouble due to the nested part of this. Here is what I have from the JS side its not much but as I mentioned Im a bit confused how to do this since it's nested.
$('table').hide();
var $table = $('<table id="UserDataTable" class="table table-hover">');
$table.append()
// THEAD
.append('<thead>').children('thead')
.append('<tr />').children('tr').append('<th>HEADING A</th>\
<th>HEADING A</th>\
<th>HEADING A</th>\
<th>HEADING A</th>\
');
// ADD TABLE TO DOM
$table.appendTo('#dynamicTable');// create tabl
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css" integrity="sha384-HSMxcRTRxnN+Bdg0JdbxYKrThecOKuH5zCYotlSAcp1+c8xmyTe9GYg1l9a69psu" crossorigin="anonymous">
<div class="container">
<div id="dynamicTable">
</div><br>
</div>