check if click is inside div javascript

Solutions on MaxInterview for check if click is inside div javascript by the best coders in the world

showing results for - "check if click is inside div javascript"
Antonio
29 Jul 2018
1var container = document.getElementsByClassName('container')[0];
2document.addEventListener('click', function( event ) {
3  if (container !== event.target && !container.contains(event.target)) {    
4    console.log('clicking outside the div');
5  }
6});
7