A div2 dobozt szeretnénk mozgatni.
<!-- ... --> <div id="div1" ondrop="drop(event)" ondragover="allowDrop(event)"></div> <div id="div2" draggable="true" ondragstart="drag(event)"></div> <!-- ... -->
#div1 { width: 100px; height: 50px; background-color: aqua; } #div2 { width: 100px; height: 50px; background-color:burlywood; }
function drag(event) { event.dataTransfer.setData('actual', event.target.id) } function drop(event) { const data = event.dataTransfer.getData('actual') event.target.appendChild(document.getElementById(data)) console.log(data) } function allowDrop(event) { event.preventDefault() }