HTML Drag and Drop API

❮ PreviousNext ❯

#div1, #div2 { float: left; width: 100px; height: 35px; margin: 10px; padding: 10px; border: 1px solid black; } 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)); }

Drag and Drop

Drag the image back and forth between the two div elements.

Leave a Reply

Your email address will not be published. Required fields are marked *