Skip to content

Instantly share code, notes, and snippets.

@yaru22
Forked from abidibo/path.js
Last active August 29, 2015 14:17
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 yaru22/6bd0b0f9e4466aa9c661 to your computer and use it in GitHub Desktop.
Save yaru22/6bd0b0f9e4466aa9c661 to your computer and use it in GitHub Desktop.
// requires mootools selectors
var path = function path(element) {
if(element.get('id')) {
return '#' + element.get('id');
}
if(element == document.body) {
return 'body';
}
var prev_equal_siblings_length = element.getAllPrevious(element.get('tag')).length;
var part = element.get('tag') + ':nth-of-type(' + (prev_equal_siblings_length + 1) + ')';
return path(element.getParent()) + ' > ' + part;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment