Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

javascript traversing

Traversing means "move through", are used to "find" (or select) HTML elements based on their relation to other elements. Start with one selection and move through that selection until you reach the elements you desire.

By using 

Closest
const closestElement = targetElement.closest(selector);

Siblings
const previous = element.previousSibling;
const next = element.nextSibling;

Children
const container = document.querySelector('#container');
const children = container.childNodes;

Parent
const current = document.querySelector('#main');
const parent = current.parentNode;
 
PREVIOUS NEXT
Tagged: #javascript #traversing
ADD COMMENT
Topic
Name
3+6 =