I'm working with drag and drop , and need to detect with JS when the element is not dropped in the marked zone, ie when I drag the element but loosen it and it goes back to its place.
Is it possible to do this?
HTML + Javascript
function allowDrop(ev){
ev.preventDefault();
}
function drag(ev){
ev.dataTransfer.setData("text", ev.target.id);
}
function drop(ev){
ev.preventDefault();
var element = ev.dataTransfer.getData("text");
ev.target.appendChild(document.getElementById(element));
}
<div id="drag1" draggable="true" ondragstart="drag(event)"></div>
<div id="div1" ondrop="drop(event)" ondragover="allowDrop(event)"></div>