JSFiddle - React, Tailwind, and code Playground
HTML
<div>
<div>
Not selected
</div>
<div>
Selected Text
</div>
</div>
JavaScript
function getElementPath(element)
{
return "//" + $(element).parents().andSelf().map(function() {
var $this = $(this);
var tagName = this.nodeName;
if ($this.siblings(tagName).length > 0) {
tagName += "[" + $this.prevAll(tagName).length + "]";
}
return tagName;
}).get().join("/").toUpperCase();
}
$(document).ready(function() {
$("div").click(function(event) {
event.stopPropagation();
window.alert(getElementPath(this));
});
});