preventDefault and stopPropagation
Control default behavior and bubbling.
Controlling Event Behavior
Two mechanisms let you control events: stopping the browser’s default action and stopping the event from traveling through the DOM.
Default Actions
Many elements have built-in default behaviors: links navigate, form submits reload, checkboxes toggle. These happen unless you intervene.
All lessons in this course
- addEventListener Basics
- The Event Object
- preventDefault and stopPropagation
- Keyboard and Mouse Events