Is there any way to change jquery code below to find xpath location of the html code. Or is there unique jquery code regardless of the html (html is changing) Please visit: http://jsbin.com/uhude3/19/edit becouse i'm writting code there. What I need is - where i'm clicking on element to show me xpath location of div,span,p,@href... ... etc.
jQuery(function($) {
$(".rightArrow").click(function() {
var rightArrowParents = [];
$(this).parents().not('html').each(function() {
var entry = this.tagName.toLowerCase();
if (this.className) {
entry += "." + this.className.replace(/ /g, '.');
}
rightArrowParents.push(entry);
});
rightArrowParents.reverse();
alert(rightArrowParents.join(" "));
});
});
and how to change this my code UP with rhis below:
function getXPath( element )
{
var xpath = '';
for ( ; element && element.nodeType == 1; element = element.parentNode )
{
var id = $(element.parentNode).children(element.tagName).index(element) + 1;
id > 1 ? (id = '[' + id + ']') : (id = '');
xpath = '/' + element.tagName.toLowerCase() + id + xpath;
}
return xpath;
}
to when I click I get a xpath. How to combine this two codes??? http://jsbin.com/uhude3/19/edit