I need to construct the following HTML dynamically
<tr>
<td><label class="mt-checkbox mt-checkbox-outline"><input type="checkbox" class="chkclass">A<span></span></label></td>
<td><label class="mt-checkbox mt-checkbox-outline"><input type="checkbox" class="chkclass">B<span></span></label></td>
<td><label class="mt-checkbox mt-checkbox-outline"><input type="checkbox" class="chkclass">C<span></span></label></td>
<td><label class="mt-checkbox mt-checkbox-outline"><input type="checkbox" class="chkclass">D<span></span></label></td>
</tr>
<tr>
<td><label class="mt-checkbox mt-checkbox-outline"><input type="checkbox" class="chkclass" >E<span></span></label></td>
<td><label class="mt-checkbox mt-checkbox-outline"><input type="checkbox" class="chkclass">F<span></span></label></td>
<td><label class="mt-checkbox mt-checkbox-outline"><input type="checkbox" class="chkclass" >G<span></span></label></td>
<td><label class="mt-checkbox mt-checkbox-outline"><input type="checkbox" class="chkclass">H<span></span></label></td>
</tr>
As you can see each tr should contain only 4 columns
This is my code
While Initially showing the data i am using this piece of code and this is working fine
<table class="table" id="tagstable">
<tbody>
</tbody>
</table>
var myarray = ["A", "B", "C", "D", "E", "F", "G", "H"]
$(document).ready(function()
{
var html = ''
for (var i = 0; i < myarray.length; i++)
{
html += '<td><label class="mt-checkbox mt-checkbox-outline"><input type="checkbox" class="chkclass">' + myarray[i] + '<span></span></label></td>';
if ((i + 1) % 4 == 0) html += '</tr><tr>';
}
$("#tagstable tbody").append('<tr>' + html + '</tr>');
});
But when a user adds a new tag dynamically by clicking on Add New Tag button
I couldn't able to achive that functionality , could you please let me know how to display tags as per the above structure
In the below fiddle ,this can be reproduced if clicked on Add new tag button more than 5 times
https://jsfiddle.net/dHZS9/717/
Could you please let me know how to resolve this