Last active
November 5, 2022 14:30
-
-
Save amirrajan/1cadf3eb196c23070a53842ab5be0403 to your computer and use it in GitHub Desktop.
Drag and drop from w3schools
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE HTML> | |
<html> | |
<head> | |
<style> | |
#div1 { | |
width: 350px; | |
height: 70px; | |
padding: 10px; | |
border: 1px solid #aaaaaa; | |
} | |
</style> | |
<script> | |
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)); | |
} | |
</script> | |
</head> | |
<body> | |
<p>Drag the W3Schools image into the rectangle:</p> | |
<div id="div1" ondrop="drop(event)" ondragover="allowDrop(event)"></div> | |
<br> | |
<div id="drag1" src="img_logo.gif" style="border: solid 1px purple; display: block; width: 150px; height: 50px;" draggable="true" ondragstart="drag(event)" width="336" height="69">Drag Me Up There</div> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment