I've seen some tutorials and articles using addEventListener and the vast majority of time useCapture
is set to false.
Must I set useCapture
to false when I use addEventListener?
I've seen some tutorials and articles using addEventListener and the vast majority of time useCapture
is set to false.
Must I set useCapture
to false when I use addEventListener?
There are two ways to attach handlers to events: event capturing and event bubbling. They're two slightly different ways of handling events, and there isn't a "right" answer: in most cases you could use either one. But, that being said, event bubbling is the much more popular approach, which is why useCapture
is almost always specified as false in examples.
With modern browsers, useCapture
is optional and defaults to false
anyways, but for compatibility with older browsers, it's often specified explicitly anyways.
You can read about the difference between capturing and bubbling here: What is event bubbling and capturing?