Skip to content

Bubbling

By default, events bubble up from the target element through its ancestors to the document. This allows parent elements to handle events from their children.

flowchart TD
A["document"]
B["<html>"]
C["<body>"]
D["<div>"]
E["<button> ★ Target"]
A -->|"8. Bubbling ↑"| B
B -->|"7. Bubbling ↑"| C
C -->|"6. Bubbling ↑"| D
D -->|"5. Bubbling ↑"| E
document.querySelector('button').addEventListener('click', () => {
console.log('Button clicked');
});
document.querySelector('div').addEventListener('click', () => {
console.log('Div clicked — bubbling!');
});
document.body.addEventListener('click', () => {
console.log('Body clicked — bubbling!');
});
// Clicking the button logs:
// 'Button clicked'
// 'Div clicked — bubbling!'
// 'Body clicked — bubbling!'

Some events do NOT bubble: focus, blur, mouseenter, mouseleave, scroll, load, unload.

  • Events bubble from target up through ancestors
  • Default behavior — most events bubble
  • Enables event delegation pattern
  • Some events (focus, blur) don’t bubble