window.addEventListener('click', function(e){ if (document.getElementById('clickbox').contains(e.target)){ // Clicked in box } else{ // Clicked outside the box } });