I want to add button element to each list element (JavaScript).
This is my code. I used fro loop. In the output, only the last element of the list is getting the button element. What am I doing wrong.
function createButtonElement() {
var btn = document.createElement("button"); `
btn.appendChild(document.createTextNode("Delete Me"));
var a = document.querySelectorAll("li");
for(var v =0; v<a.length;v++)
{
a[v].appendChild(btn);
}
}
lielement and don't forget to give it a click event listener inside that loop as well as an id or some dataset info in order to differenciate each button