coure2011
coure2011

Reputation: 42454

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

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

Upvotes: 2

Views: 48

Answers (1)

abgregs
abgregs

Reputation: 1380

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

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

Upvotes: 2

Related Questions