I am learning about Drag & Drop. I have copied a W3Schools example in JSFiddle.
The W3School example calls preventDefault()
in the drop event:
function drop(ev) {
ev.preventDefault();
var data=ev.dataTransfer.getData("Text");
ev.target.appendChild(document.getElementById(data));
}
Yet, I don't understand the need when reading documentation. When I remove this call, the example still works fine:
function drop(ev) {
var data=ev.dataTransfer.getData("Text");
ev.target.appendChild(document.getElementById(data));
}
So, what is the use of this call to preventDefault()
? Do I really need it? If yes why?