Если вы собираетесь генерировать элементы в DOM, вы должны добавить их к элементу, от которого они ожидаются.Это основной пример создания элементов и добавления их к родителю.Надеемся, это даст вам представление о том, как может работать ваша логика.
var $body = $(document.body);
//make a table
var $table = $('<table>');
//make a row
var $row = $('<tr>');
//make a column
var $col = $('<td>');
//put something in the column
$col.append('Hey there!');
//put the column in the row
$row.append($col);
//put the row in the table
$table.append($row);
//put the table in the body
$body.append($table);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
Или вы можете сначала создать разметку в виде строки, прежде чем добавлять ее.
var $body = $(document.body);
var html = '';
//make a table
html += '<table>';
//make a row
html += '<tr>';
//make a column
html += '<td>';
//put something in the column
html += 'Hey there!';
//close the column
html += '</td>';
//close the row
html += '</tr>';
//close the table
html += '</table>';
//put the table in the body
$body.append(html);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>