I have to dinamically create nested divs using jquery .append()
But by this code:`
html=$("<div class='table'>")
.append($("<div class='row'>"))
.append($("<label>Denominazione Gruppo</label>"))
.append($("<input type='text' id='denominazione'>"));
$("#content").empty();
$("#content").append(html);`
i get this wrong output
<div id="content">
<div class="table">
<div class="row"></div> //this closed tag should not be here!
<label>Denominazione Gruppo</label>
<input type="text" id="denominazione">
</div>
</div>
Where i wrong? Thank you.
You need to append the input and label to the row element
html = $("<div class='table'>").append($("<div class='row'>")
.append("<label>Denominazione Gruppo</label>")
.append("<input type='text' id='denominazione'>"));
$("#content").empty();
$("#content").append(html);
Demo: Fiddle
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With