Skip to content

Instantly share code, notes, and snippets.

@johnsardine
Created December 18, 2019 11:46
Show Gist options
  • Save johnsardine/ba1c79630d8c7c230c4b418d8820198b to your computer and use it in GitHub Desktop.
Save johnsardine/ba1c79630d8c7c230c4b418d8820198b to your computer and use it in GitHub Desktop.
export function nodeTreePath(element) {
const path = [];
let currentEl = element;
while (currentEl) {
path.push(currentEl);
currentEl = currentEl.parentElement;
}
return path;
}
export function getEventPath(event) {
if (event.path) {
return event.path;
}
if (event.composedPath) {
return event.composedPath();
}
return nodeTreePath(event.target);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment