Created
September 2, 2015 00:36
-
-
Save Seich/4662ee7ac998328ba32a 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
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