I'm running into an issue while trying to add buttons to the existing list items. Below is my code snippet:
function buttonDelete() {
var items = document.getElementsByTagName("li");
var button = document.createElement("button");
button.appendChild(document.createTextNode("Delete"));
items.appendChild(button);
button.onclick = function() {
this.remove();
items.remove();
}
}
buttonDelete();
Unfortunately, I keep encountering an error message: Uncaught TypeError: items.appendChild is not a function.
When I try selecting only one li item (var items = document.querySelector("li");), it successfully adds the button but only for the first item in the list.