-
Notifications
You must be signed in to change notification settings - Fork 22.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Explain event handlers and capturing #13877
Conversation
@OndeVai, can you review this? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your PR! I think it would be better to have this after
content/files/en-us/learn/javascript/building_blocks/events/index.md
Lines 630 to 635 in 056aed1
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 `<video>` element outwards to the `<html>` element. | |
Along the way: | |
- 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. |
I think it could also be more precise, something like:
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 thecapture
option to addEventListener().
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressing requested changes
Thanks for the update! This section:
...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:
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changes requested in #13877 (comment).
@timeowilliams This seems to be waiting on your response to #13877 (comment) |
Closing in favour of #20013. |
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
#13749
Related issues
Fixes #13749
Metadata