This question already has an answer here:
var whichSelected = document.querySelectorAll(".selected");
for(var i = 0; i < whichSelected.length; i++) {
var clone = whichSelected[i].cloneNode(false);
clone.addEventListener("click", function() {createOutline(clone)});
document.body.appendChild(clone);
}
I have no idea why the event listener will not work on the clones. Any ideas is appreciated!
You are setting the
z-index
of the copied node to-1
, so when clicking, you click onbody
.Also, the
id
is the same as the copied node, you might want to change this.