Skip to content

Instantly share code, notes, and snippets.

@eramdam
Created March 18, 2018 05:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eramdam/0d1f42e9f4a6077b3f87e6c5f9b2d274 to your computer and use it in GitHub Desktop.
Save eramdam/0d1f42e9f4a6077b3f87e6c5f9b2d274 to your computer and use it in GitHub Desktop.
const getSelector = el => {
let sel = [];
let currEl = el;
while (!!currEl) {
sel = [`${currEl.tagName.toLowerCase()}.${currEl.className.trim().replace(/\s+/g, '.')}`, ;
currEl = currEl.parentElement;
}
return sel.join(' > ');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment