-
-
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(' > '); | |
} |
It's for use in situations where I have a read only copy of the DOM.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This seems pretty expensive, why not just give it a unique ID?