<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<style>
html,body{
height: 100%;
overflow: hidden;
}
#box{
position: absolute;
top: 0;
left: 0;
width: 100px;
height: 100px;
display: inline-block;
background-color: red;
cursor: move;
}
#container{
position: relative;
width: 300px;
height: 200px;
margin: 30px auto;
box-sizing: border-box;
border: 2px solid lightseagreen;
}
</style>
</head>
<body>
<div id="box" draggable="true"></div>
<div id="container"></div>
<script>
box.ondragstart = function(ev){
ev.dataTransfer.setData('text/plain',ev.target.id)
}
container.ondragover = function(ev){
ev.preventDefault()
}
container.ondrop = function(ev){
ev.preventDefault()
let _ID=ev.dataTransfer.getData('text/plain'),
_ELE = document.getElementById(_ID);
container.appendChild(_ELE)
console.log(_ID)
}
</script>
</body>
</html>