content icon indicating copy to clipboard operation
content copied to clipboard

Explain event handlers and capturing

Open timeowilliams opened this issue 2 years ago • 4 comments

Summary

Added statement about how the capture process within event lifecycles is optional.

Motivation

To allow readers of the documentation get a better grasp of the three stages and what is/not optional.

Supporting details

https://developer.mozilla.org/en-US/docs/Learn/JavaScript/Building_blocks/Events#bubbling_and_capturing_explained https://github.com/mdn/content/issues/13749

Related issues

Fixes #13749

Metadata

  • [ ] Adds a new document
  • [X] Rewrites (or significantly expands) a document
  • [ ] Fixes a typo, bug, or other error

timeowilliams avatar Mar 15 '22 04:03 timeowilliams

Preview URLs

Flaws

URL: /en-US/docs/Learn/JavaScript/Building_blocks/Events Title: Introduction to events on GitHub Flaw count: 1

  • broken_links:
    • Can't resolve https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener

External URLs

URL: /en-US/docs/Learn/JavaScript/Building_blocks/Events Title: Introduction to events on GitHub

(this comment was updated 2022-03-26 07:06:30.971606)

github-actions[bot] avatar Mar 15 '22 04:03 github-actions[bot]

@Ondevai, can you review this?

teoli2003 avatar Mar 15 '22 04:03 teoli2003

Thanks for the update!

This section:

In modern browsers, by default, all event handlers are registered for the bubbling phase. So in our current example, when you select the video, the event bubbles from the

  • It finds the click handler on the video element and runs it, so the video first starts playing.
  • It then finds the click handler on the videoBox element and runs that, so the video is hidden as well.

...is talking about the bubbling phase. By splicing stuff about capturing in, it doesn't make sense any more.

I think the part about enabling capturing should go after this, like:

In modern browsers, by default, all event handlers are registered for the bubbling phase. So in our current example, when you select the video, the event bubbles from the

  • It finds the click handler on the video element and runs it, so the video first starts playing.
  • It then finds the click handler on the videoBox element and runs that, so the video is hidden as well.

In modern browsers, by default, event handlers are not registered for the capturing phase. To register an event handler for the capturing phase, instead of the bubbling phase, pass the useCapture argument or the capture option to addEventListener().

Also, when your edit says "*Generally when event handlers are added to HTML code" - what work is "Generally" doing here? Usually when I see this word I think it means "usually but not always", and in documentation this makes me think, "when isn't it?" and if the documentation doesn't go on to explain that case, then I am left confused.

wbamberg avatar Mar 26 '22 17:03 wbamberg

@timeowilliams This seems to be waiting on your response to https://github.com/mdn/content/pull/13877#issuecomment-1079742220

sideshowbarker avatar Jul 12 '22 06:07 sideshowbarker

Closing in favour of https://github.com/mdn/content/pull/20013.

wbamberg avatar Aug 26 '22 23:08 wbamberg