var container = document.getElementsByClassName('container')[0];
document.addEventListener('click', function( event ) {
if (container !== event.target && !container.contains(event.target)) {
console.log('clicking outside the div');
}
});
// Get arbitrary element with id "my-element"
var myElementToCheckIfClicksAreInsideOf = document.querySelector('#my-element');
// Listen for click events on body
document.body.addEventListener('click', function (event) {
if (myElementToCheckIfClicksAreInsideOf.contains(event.target)) {
console.log('clicked inside');
} else {
console.log('clicked outside');
}
});