Created
October 19, 2022 05:50
-
-
Save shobhit/e5c8d29c52c76aba93bfc1432801a5f2 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
const getCssSelector = (el) => { | |
let path = [], parent; | |
while (parent = el.parentNode) { | |
path.unshift(`${el.tagName}:nth-child(${[].indexOf.call(parent.children, el)+1})`); | |
el = parent; | |
} | |
return `${path.join(' > ')}`.toLowerCase(); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment