I am creating a question generator with a drag and drop question and I have a problem to check which element is dropped in which drag zone?
I don't honestly know if it's possible with Javascript only or do I need another library because I'm using vanilla JS.
function allowDrop(ev) {
ev.preventDefault();
}
function drag(ev) {
ev.dataTransfer.setData("text", ev.target.id);
}
function drop(ev) {
ev.preventDefault();
var data = ev.dataTransfer.getData("text");
ev.target.appendChild(document.getElementById(data));
}
#div1 {
width: 350px;
height: 70px;
padding: 10px;
border: 1px solid #aaaaaa;
}
<p>Drag the image into the rectangle:</p>
<div id="div1" ondrop="drop(event)" ondragover="allowDrop(event)"></div>
<br>
<img id="drag1" src="http://localhost/source1.png" draggable="true" ondragstart="drag(event)" width="336" height="69">