Listen on the box and report when a click on the button reaches it.
Acceptance criteria
- 1.#out should show box heard it.
JavaScript Tutorial · JavaScript Events
These 10 tasks go with the JavaScript Event Bubbling chapter. 5 of them ask you to build something small from scratch; 5 give you code that is already broken and ask you to work out why. Set aside about 90 minutes for the whole set, though you can do them in any order.
Nothing here is marked by a person. When you press Submit, the editor checks your code against the points listed under each task and tells you straight away what passed and what didn't (you need a free account to submit). If you get stuck, there are hints, and a worked solution once you've had a go. The first 2 tasks are free; the rest are part of the practice plan.
If it's been a while since you read the chapter, here is how it starts: “An event fired on an element travels up through its ancestors.” .
1.See a click bubbleexercise · easy · 10 min
Listen on the box and report when a click on the button reaches it.
Passes when: #out should show box heard it.
2.Record the bubbling orderexercise · easy · 10 min · practice plan
Report the order the three handlers run in.
Passes when: #out should show inner middle outer.
3.Stop the bubbleexercise · easy · 10 min · practice plan
Stop the click reaching the box and report only inner.
Passes when: #out should show inner only.
4.Listen while capturingexercise · easy · 10 min · practice plan
Use capturing so the outer handler runs before the inner one.
Passes when: #out should show outer first.
5.Show target does not changeexercise · medium · 10 min · practice plan
Listen on the box and report the id of target and currentTarget.
Passes when: #out should show inner then outer.
6.Fix the order recorded backwardsbug fix · easy · 8 min
Bubbling runs the innermost handler first.
Passes when: Clicking should make #out show inner then outer.
7.Fix preventDefault used to stop bubblingbug fix · easy · 8 min · practice plan
preventDefault cancels the browser action, not the travel.
Passes when: Clicking should make #out show inner only.
8.Fix the missing capturing flagbug fix · easy · 8 min · practice plan
Without true the outer handler runs after the inner one.
Passes when: Clicking should make #out show outer first.
9.Fix currentTarget used as the clicked elementbug fix · easy · 8 min · practice plan
target is where the click started, however far it travels.
Passes when: Clicking should make #out show inner then outer.
10.Fix the non-bubbling focus eventbug fix · easy · 8 min · practice plan
focus does not bubble, so focusin is needed on the parent.
Passes when: #out should show box heard the focus.
Between them these tasks cover Bubbling, Capturing and stopPropagation.
Looking for a different chapter? See every practice set, or switch to the interview theory questions.