Skip to content

Instantly share code, notes, and snippets.

@amirrajan
Last active November 5, 2022 14:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amirrajan/1cadf3eb196c23070a53842ab5be0403 to your computer and use it in GitHub Desktop.
Save amirrajan/1cadf3eb196c23070a53842ab5be0403 to your computer and use it in GitHub Desktop.
Drag and drop from w3schools
<!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