Is there a way to append HTML using template literals in the DOM without overwriting what was currently posted?
I have a huge block of HTML that I need to post for a list that is being created, where a user is able to post their input.
Every time the task is submitted, it overwrites the current submission. I need it to append underneath.
This is the fiddle for demonstration purpose.
HTML:
<div class="main-content">
<form class="new-items-create">
<label>Name:</label>
<input
placeholder=" A Name"
id="name"
/>
<button class="subBtn">Submit</button>
</form>
</div>
<span class="new-name"></span>
JavaScript:
form.addEventListener("submit", addItem);
function addItem(event) {
event.preventDefault();
let htmlStuff = `
<div class="main">
<div class="a name">
<span>${name.value}</span>
</div>
<div>
`;
itemCreated.innerHTML = htmlStuff;
}
itemCreated.innerHTML += htmlStuff