I have an app in which I dynamically add unordered lists to a div with id="rows"
Each time I add an unordered list, I want to add list items to it.
My code does not add the list items to the list. Instead, it adds the list items as children of the div rather than children of the unordered list.
Here is the HTML
<body>
<div id="colNames">
<button class="ui-button ui-widget ui-corner-all" id="add-column">Add Column</button>
<button class="ui-button ui-widget ui-corner-all" id="clear-column-list">Clear Columns</button>
<ul id="column-list">
</ul>
</div>
<div id="rows">
<button class="ui-button ui-widget ui-corner-all" id="add-row">Add Row</button>
</div>
<div id="buttons">
<button class="ui-button ui-widget ui-corner-all" id="create-table">Generate Table Markdown</button>
</div>
</body>
Here is the code that is not working
let colNameArray = ["a", "b"];
let newRow = $("#rows").append("<ul></ul>");
for (let i in colNameArray) {
let name = colNameArray[i];
$(newRow).append("<li><p> " + name + "</p><input type='text'></li>");
}
My project has separate files for html, script, and css. Let me know if you need to see the entire project.
...
` for final insertion. – tadman Aug 13 '23 at 20:38");` returns `#rows`. `$("
").appendTo("#rows")` returns the newly added `ul` – freedomn-m Aug 14 '23 at 15:26