JSFiddle - React, Tailwind, and code Playground
by ululami
HTML
<div id="box"></div>
CSS
*{
margin: 0;
padding: 0;
}
#box{
width: 50px;
height: 50px;
background: red;
position: absolute;
}
JavaScript
var x = 0;
var y = 0;
function moveBox(event){
x = event.clientX;
y = event.clientY;
document.getElementById('box').style.left = x + 'px';
document.getElementById('box').style.top = y + 'px';
}
document.addEventListener('click', function(event){
moveBox(event);
});