I'm trying to move multiple images by defining each one with a for loop. Below is the code I have:
var elem = document.querySelectorAll(".yikama");
var el;
for (i = 0; i < elem.length; i++) {
var el = elem[i]
el.addEventListener("mousedown", start)
function start() {
addEventListener("mousemove", move)
}
function move(b) {
b = b || event;
el.style.left = b.pageX - 290 + "px";
el.style.top = b.pageY - 190 + "px";
}
el.addEventListener("mouseup", function () {
removeEventListener("mousemove", move);
})
}
However, I encountered an error: Uncaught TypeError: Cannot read property 'addEventListener' of undefined at line 1:141. How can I resolve this issue?