webcomponents - hide dropdown menu on window.onclick
Clash Royale CLAN TAG #URR8PPP webcomponents - hide dropdown menu on window.onclick dropdown menu is created in shadowDOM almost perfect, but the problem is how to hide the dropdown menu when click on any where else in window class NavComponent extends HTMLElement { constructor() { super(); let template = document.currentScript.ownerDocument.querySelector('template'); let clone = document.importNode(template.content, true); let root = this.attachShadow({ mode: 'open' }); root.appendChild(clone); } connectedCallback() { let ddc = this.shadowRoot.querySelectorAll('.dropdowncontainer') let dd = this.shadowRoot.querySelectorAll('.dropdown'); let ddc_length = ddc.length for (let index = 0; index < ddc_length; index++) { ddc[index].addEventListener('click', e => { dd[index].classList.toggle('show'); }); } ...