Javascript Function [getParents(sourceElement)] to Get All Parents

Javascript Function Code [getParents(sourceElement)] to Get All Parents Recursively Traveling up the Parent Tree Storing Parent Elements in Array and Returning

Home Short:

The below code is a simple Javascript function that allows to input an element [sourceElement] and recursively travel up the parent tree storing all of the parents in array and returning the array.

Example use:

The array of parent elements return can be manipulated and have properties returned just like any other html element in JavaScript.

S
H
A
R
E