JSFiddle - React, Tailwind, and code Playground
HTML
<body>
<div class="pics">
<div id="area1" ondrop="dropIt(event);" ondragover="event.preventDefault();">
<img id="drag1" src="https://iconbug.com/data/29/128/1cc6b61217921b624db0cd6cfd6d1360.png" draggable="true" ondragstart="dragIt(event);" style />
</div>
<div id="area2" ondrop="dropIt(event);" ondragover="event.preventDefault();">
</div>
<div id="area3" ondrop="dropIt(event);" ondragover="event.preventDefault();">
</div>
</div>
<div class="nums">
<span>1</span>
<span>2</span>
<span>3</span>
</div>
</body>
CSS
div[id^="area"] {
float: left;
width: 150px;
height: 150px;
margin: 3px;
padding: 3px;
border: 1px dotted #333333;
background-color: #fefefe;
}
span {
float: left;
width: 150px;
margin: 3px;
padding: 3px;
border: 1px solid #999999;
color: #333333;
}
.pics,
.nums {
clear: both;
text-align: center;
}
JavaScript
//function called when drag starts
function dragIt(theEvent) {
//tell the browser what to drag
theEvent.dataTransfer.setData("Text", theEvent.target.id);
}
//function called when element drops
function dropIt(theEvent) {
//get a reference to the element being dragged
var theData = theEvent.dataTransfer.getData("Text");
//get the element
var theDraggedElement = document.getElementById(theData);
//add it to the drop element
theEvent.target.appendChild(theDraggedElement);
//instruct the browser to allow the drop
theEvent.preventDefault();
}