Reputation: 1081
I have this code that is supposed to create 10 draggable img elements
var container = document.getElementById("container");
for (var i = 0; i < 10; i++) {
var trash = GenerateTrash(i);
container.appendChild(trash);
}
function GenerateTrash(i) {
var trash = document.createElement("img");
trash.src = "crumpled-paper.png";
trash.id = i;
trash.draggable = true;
trash.ondragstart = function () { ev.dataTransfer.setData("dragged-id", ev.target.id); };
return trash;
}
However, when I run it through the debugger, the "ondragstart" function simply isn't there. Help ?
Upvotes: 0
Views: 35
Reputation: 8310
Didn't you forgot to include ev
parameter into your anonymous function?
Upvotes: 1