$('#elem').mouseleave(checkMouseLeave()); function checkMouseLeave() { document.onmouseup = fclear; document.addEventListener("onmouseup", fclear, false); }