Skip to content

Instantly share code, notes, and snippets.

@Seich
Created September 2, 2015 00:36
Show Gist options
  • Save Seich/4662ee7ac998328ba32a to your computer and use it in GitHub Desktop.
Save Seich/4662ee7ac998328ba32a to your computer and use it in GitHub Desktop.
function fullPath(el){
var names = [];
while (el.parentNode){
if (el.id){
names.unshift('#'+el.id);
break;
}else{
if (el==el.ownerDocument.documentElement) names.unshift(el.tagName);
else{
for (var c=1,e=el;e.previousElementSibling;e=e.previousElementSibling,c++);
names.unshift(el.tagName+":nth-child("+c+")");
}
el=el.parentNode;
}
}
return names.join(" > ");
}
console.log( fullPath( $('input')[0] ) );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment