JSFiddle - React, Tailwind, and code Playground
HTML
<div href="#" id=console>
<span id="square"></span>
</div>
CSS
html,
body {
padding: 0;
margin:0;
min-width: 100%;
min-height: 100%;
}
#console {
display: block;
background: #EEE;
height:300px;
overflow: auto;
}
#square {
display: block;
position: absolute;
width: 80px;
height: 80px;
background-color: red;
left: 100px;
top: 50px;
}
}
JavaScript
$(document).ready(function() {
var $body = $('body');
var $console = $('#console');
var detectMouse = function(e){
if (e.type === 'mousedown') {
$console.prepend('<p style="color:red">' + e.type + '</p>');
}
else {
$console.prepend('<p style="color:green">' + e.type + '</p>');
}
// remove event bindings, so it only runs once
$body.off('mousedown touchstart', detectMouse);
}
// attach both events to body
$body.on('mousedown touchstart', detectMouse);
});