JSFiddle - React, Tailwind, and code Playground
by Ting-Yuan Chang
HTML
<div class="log">
</div>
JavaScript
var timeout;
$(document).click( function() {
var timeoutSecond = 5;
var datetime = new Date().toLocaleString();
$('.log').append('<p>' + datetime + ': detect click</p>');
if(timeout != undefined) {
clearTimeout(timeout);
}
timeout = setTimeout(function() {
var datetime = new Date().toLocaleString();
$('.log').append('<p>' + datetime + ': ' + timeoutSecond + ' seconds past</p>');
}, timeoutSecond * 1000);
});