<! DOCTYPE html>
<script type= "Text/javascript" >
function AllowDrop (EV)
{
Ev.preventdefault ();
}
function drag (EV)
{
Ev.dataTransfer.setData ("Text", ev.target.id);
}
What to drag-ondragstart and SetData ()
Then, specify what happens when the element is dragged.
In the example above, the Ondragstart property invokes a function, drag (event), which specifies the data to be dragged.
The Datatransfer.setdata () method sets the data type and value of the dragged data:
function Drop (EV)
{
Where to put it-ondragover
The OnDragOver event specifies where to place the dragged data.
By default, data/elements cannot be placed in other elements. If you need to set allow placement, we must block the default handling of elements.
This is done by invoking the event for OnDragOver events. Preventdefault () Method:
Ev.preventdefault ();
var data=ev.datatransfer.getdata ("Text");
Ev.target.appendChild (document.getElementById (data));
}
</script>
<body>
<div id= "Div1" ondrop= "Drop (event)"
Ondragover= "AllowDrop (event)" ></div>
Set elements to be dragged and dropped
First, to make an element draggable, set the Draggable property to True:
ondragstart= "Drag (Event)" Width= "336" height= ""/>
</body>
HTML5 Drag and drop instance