I've got a function that is supposed to append some text to all the images in a <section>
on my page. Here's the function:
function addDeleteButton(nodeList){
var text = document.createElement("p");
text.innerHTML = "Delete";
text.style.position = "absolute";
text.style.bottom = "3";
text.style.right = "3";
text.style.zIndex = "10";
for(var i = 0; i<nodeList.length; i++){
nodeList[i].onmouseover = function(){
nodeList[i].appendChild(text);
}
}
}
But the problem is, that when I hover over the element, I get this error in the console:
TypeError : Cannot read property "appendChild" of undefined?
The function is executed when the window loads, so there's no problem with that, and the handler also works fine.
What's the problem? Thanks.