ancestor
Any node above a given node in the DOM tree: its parent, the parent's parent and so on up to the document.
In more detail
parentNode and parentElement give the direct parent. closest() walks up the ancestor chain to find the nearest match, and events bubble up through the same chain.
Related terms
- descendant — Any node below a given node in the DOM tree: its children, their children and so on.
- sibling — A node that shares the same parent as another node in the DOM tree.
- Element.closest() — The DOM method that starts at an element and walks up through its ancestors, returning the first one, itself included, that matches a selector.
- event bubbling — The way an event on an element also triggers handlers on its parent elements, one level at a time up the tree.
Taught in
- HTML Parsing, Tokenization And The Document Object Model (DOM) — Frontend Architecture & Web Platform
- Modern DOM Querying: querySelector, closest And matches — Frontend Architecture & Web Platform
- Event Phases: Capturing, Target And Bubbling Demystified — Frontend Architecture & Web Platform
- Event Delegation: Memory-Efficient Interaction Handlers — Frontend Architecture & Web Platform