0

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?

TarranJones
  • 4,084
  • 2
  • 38
  • 55
Preco Plusb
  • 615
  • 1
  • 9
  • 14

1 Answers1

4

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?

Community
  • 1
  • 1
Retsam
  • 30,909
  • 11
  • 68
  • 90