Skip to content

Instantly share code, notes, and snippets.

@andrewchilds
Created February 28, 2014 18:22
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 andrewchilds/9276676 to your computer and use it in GitHub Desktop.
Save andrewchilds/9276676 to your computer and use it in GitHub Desktop.
Simple element-to-CSS-selector conversion
function toSelector(elem) {
var css = '';
if (elem && elem.tagName) {
css += elem.tagName.toLowerCase();
if (elem.id) {
css += '#' + elem.id;
}
if (elem.className) {
css += '.' + elem.className.trim().split(' ').join('.');
}
}
return css;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment