JSFiddle - React, Tailwind, and code Playground
HTML
<div id="test">test div</div>
CSS
#test {
position:absolute;
width:100px;
height:70px;
background-color:#d2fcd9;
}
JavaScript
$('#test').click(function() {
var docHeight = $(document).height(),
docWidth = $(document).width(),
$div = $('#test'),
divWidth = $div.width(),
divHeight = $div.height(),
heightMax = docHeight - divHeight,
widthMax = docWidth - divWidth;
$div.css({
left: Math.floor( Math.random() * widthMax ),
top: Math.floor( Math.random() * heightMax )
});
});