JavaScript Event Bubbling — exercises and bug fixes
5 hands-on exercises and 5 find-the-bug challenges for the JavaScript Event Bubbling lesson. Every one is checked automatically in the browser — write the code, run it, and the tests tell you what still fails.
Exercises(5)
- 1
See a click bubble
easy10 minListen on the box and report when a click on the button reaches it.
- 2
Record the bubbling order
easy10 minReport the order the three handlers run in.
- 3
Stop the bubble
easy10 minStop the click reaching the box and report only inner.
- 4
Listen while capturing
easy10 minUse capturing so the outer handler runs before the inner one.
- 5
Show target does not change
medium10 minListen on the box and report the id of target and currentTarget.
Find the bug(5)
- 1
Fix the order recorded backwards
easy8 minBubbling runs the innermost handler first.
- 2
Fix preventDefault used to stop bubbling
easy8 minpreventDefault cancels the browser action, not the travel.
- 3
Fix the missing capturing flag
easy8 minWithout true the outer handler runs after the inner one.
- 4
Fix currentTarget used as the clicked element
easy8 mintarget is where the click started, however far it travels.
- 5
Fix the non-bubbling focus event
easy8 minfocus does not bubble, so focusin is needed on the parent.
Ready to write the code?
The editor, the automatic checks and the worked solutions open up with an account.
Open the workspace