×

Save to Google Drive

If you have a Google account, you can save this code to your Google Drive.

Google will ask you to confirm Google Drive access.

Warning: The 10th of June 2021, we will discontinue the ability to save to Google Drive.

You will still be able to access your stored code on Google Drive.

×

Open from Google Drive

If you have saved a file to Google Drive, you can open it here:

Warning: The 10th of June 2021, we will discontinue the ability to save to Google Drive.

You will still be able to access your stored code on Google Drive.

Result Size: 625 x 565
x
 
<!DOCTYPE HTML>
<html>
<head>
<style>
.droptarget {
  float: left; 
  width: 100px; 
  height: 35px;
  margin: 15px;
  padding: 10px;
  border: 1px solid #aaaaaa;
}
</style>
</head>
<body>
<p>This example uses the addEventListener() method to attach "dragstart", "drag", "dragover" and "drop" events to the document object.</p>
<p>Drag the p element back and forth between the two rectangles:</p>
<div class="droptarget">
  <p draggable="true" id="dragtarget">Drag me!</p>
</div>
<div class="droptarget"></div>
<p style="clear:both;"><strong>Note:</strong> drag events are not supported in Internet Explorer 8 and earlier versions or Safari 5.1 and earlier versions.</p>
<p id="demo"></p>
<script>
/* Events fired on the drag target */
document.addEventListener("dragstart", function(event) {
  event.dataTransfer.setData("Text", event.target.id);
});
document.addEventListener("drag", function(event) {
  document.getElementById("demo").innerHTML = "The p element is being dragged";
});
/* Events fired on the drop target */
document.addEventListener("dragover", function(event) {
  event.preventDefault();
});
×

Report a Problem:

If you want to report an error, or if you want to make a suggestion, do not hesitate to send us an e-mail:

help@w3schools.com