Home > Back-end >  How to make document.addEventLister('click' working for elements having stoppropogation?
How to make document.addEventLister('click' working for elements having stoppropogation?

Time:10-13

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));

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

CodePudding user response:

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

document.addEventListener('click', (e) => console.log(e), true)
  • Related