JavaScript DOM traversal

surfing through the HTML with JavaScript

We can get the parents and children of each document object with parentNode and children:

let objectsParent = document
    .querySelector('.object')
    .parentNode 
    
let objectsChildren = document
    .querySelector('.object')
    .children 

We can also just get the first child of each object with firstChild:

let objectsFirstborn = document
    .querySelector('.object')
    .firstChild

Last updated