is there any way to generate css path given an element ?
i saw one for javascript.
is there any way to generate css path given an element ?
i saw one for javascript.
i don't understand why this one is downvoted, a good and legitimate question
here's an (oversimplified) example on how this could be done
<div id="a">
<div class="b">
<div><span></span></div>
</div>
</div>
<script>
function getPath(elem) {
if(elem.id)
return "#" + elem.id;
if(elem.tagName == "BODY")
return '';
var path = getPath(elem.parentNode);
if(elem.className)
return path + " " + elem.tagName + "." + elem.className;
return path + " " + elem.tagName;
}
window.onload = function() {
alert(getPath(document.getElementsByTagName("SPAN")[0]));
}
</script>