Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to make document.addEventLister('click' working for elements having stoppropogation?

Working on an chrome extension and I need to get click events. I listening to events like

document.addEventListener('click', (e) => {
 // get ur work
});

The problem is it does not work if the page elements has set stopPropogation. How I can make it work?

You can see its not working by openeing the site
https://getbootstrap.com/docs/4.0/components/dropdowns/
Open inspector/console
Write document.addEventListener('click', (e) => console.log(e));

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Now try to click here n there, it will log the output on console, but if u click ‘Dropdown Button’ there is no output.

>Solution :

Pass the third arg useCapture as true in your event listener.

document.addEventListener('click', (e) => console.log(e), true)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading