Created
December 18, 2019 11:46
-
-
Save johnsardine/ba1c79630d8c7c230c4b418d8820198b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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