I have created a custom lightning web component that, if an specific div is found on the template and you're clicking outside of it, it must close the current div
constructor(){
super();
window.addEventListener('click', this.handleWindowClick.bind(this));
}
handleWindowClick = (event) => {
if(this.template.querySelector('.mydiv')){
if(this.template.querySelector('.mydiv').contains(event.target)) console.log('inside div');
else console.log('outside div');
}
}
And it's always giving me outside div
even thought I'm clicking inside .mydiv
element.
Is there anything that I'm doing wrong?