<div class="bank" id="savingsAcc0">
<div class="deleteAccButton deleteSavings">
<p>-</p>
</div>
<input type="text">
<input type="text">
</div>
I am trying to duplicate the above HTML into an already loaded DOM using Javascript. Because I am trying to do this with an already loaded DOM I cannot use document.write(). One option is to do the follow:
function nodeWantingToDuplicate() {
parentDiv = document.createElement("div");
parentDiv.class = "bank";
parentDiv.id = "savingsAcc0";
childDiv = document.createElement("div");
childDiv.class = "deleteAccButton deleteSavings";
childP = createElement("p");
childInput = document.createElement("input");
childInput.type = "text";
// then assemble elements using .appendChild, etc.
return parentDiv;
}
But I am looking for something more simple, kind of like the follow:
// of course, you cannot use .createElement() in this way.
nodeWantingToDuplicate = document.createElement("<div class='bank' id='savingsAcc0'><div class='deleteAccButton deleteSavings'><p>-</p></div><input type='text'><input type='text'></div>");
parentElement.appendChild(nodeWantingToDuplicate);
The HTML can look messing. It is the Javascript I want looking clean. Please Advise. Thank you so much!