Prev Demo
HTML5
>
Drag And Drop
Next Demo
Write code here
J
|
B
|
A
<!DOCTYPE html> <html> <head> <title>Demo</title> </head> <body> <script> function DragMe(source, e) { e.dataTransfer.setData('Text', source.id); } function DropElement(target, e) { var id = e.dataTransfer.getData('Text'); target.appendChild(document.getElementById(id)); // target.innerHTML = target.innerHTML + "<br />"; } function HighlightArea(id, isTrue) { isTrue == true ? document.getElementById(id).style.backgroundColor = "yellow" : document.getElementById(id).style.backgroundColor = ""; } </script> <body> <h1>HTML5 Drag and Drop feature example</h1> <div> <img id="img1" src="http://www.itfunda.com/Images/itfunda.gif" draggable="true" alt="itfunda.com" ondragstart="DragMe(this, event)" /> <img id="img2" src="http://www.dotnetfunda.com/images/dotnetfunda.png" draggable="true" alt="dotnetfunda.com" ondragstart="DragMe(this, event)" /> <img id="img3" src="http://farmingfunda.com/images/FarmingFunda.gif" alt="farmingfunda.com" draggable="true" ondragstart="DragMe(this, event)" /> </div> <div id="div1" style="border: 4px dashed #c0c0c0; height: 200px; width: 400px; padding: 10px; margin: 30px;" ondrop="DropElement(this, event)" onmouseout="HighlightArea(this.id, false)" ondragleave=" HighlightArea(this.id, false)" ondragenter=" HighlightArea(this.id, true)" ondragover="return false"> </div> </body> </body> </html>
Note: We DO NOT save your trial code in our database.
Output