-
-
Save robrighter/648261 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 makeSelector(el) { | |
var tag, index, stack = []; | |
while (el) { | |
tag = el.tagName; | |
index = 0 | |
while(el && el.previousSibling){ | |
el = el.previousSibling; | |
if (tag == el.tagName) | |
index += 1; | |
} | |
if(el){ | |
if(tag) | |
stack.unshift(tag + ':eq(' + (index + 0) + ')'); | |
el = el.parentNode; | |
} | |
} | |
return stack.join(' > '); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It's for use in situations where I have a read only copy of the DOM.