I'm, struggling a little bit trying to understand the way .append and .html works.
I have this code which generates a new <li>
element when clicking a button:
The way that it's written below works fine. The thing is that if instead of .html() I use .append() it add a new <li>
plus all the others, not just ONE <li>
Can someone explain to me why does it happen? Thanks in advance :)
const showTask = () =>{
let itemHtml = "";
toDoList.forEach((item, index)=>{
itemHtml +=
`<li class="item ${item.isCompleted == true ? " item-is-done" : ""}" id="${index}"><input type="checkbox" class="checkbox"><span>${item.task}</span>
<button type="button" class="remove" onClick="deleteTask(${index})"><i class="bi bi-trash" id="remove-btn"></i></button>
</li>`;
});
$(".list").html(itemHtml);
};