Bug Bounties

Detect outside click with only few lines of Javascript code

I found a pretty straight solution for this problem. You can add an event listener targeting an element by his id like so



window.addEventListener('mouseup',function(event){
        var pol = document.getElementById('pol');
        if(event.target != pol && event.target.parentNode != pol){
            pol.style.display = 'none';
        }
  }); 

⇐ Debouncing a search query in VuejsAdvent of code day one solutions  ⇒