setTimeout
var timer;
$(document)
.on('mouseenter focusin', function() {
clearTimeout(timer);
})
.on('mouseleave focusout', function() {
timer = setTimeout(function() {
if (!$('div:hover').length) {
$('div').remove();
}
}, 500);
});