getAncestors
Returns all the ancestors of an element from the document root to the given element.
- Use
Node.parentNode
and awhile
loop to move up the ancestor tree of the element. - Use
Array.prototype.unshift()
to add each new ancestor to the start of the array.