JSFiddle - React, Tailwind, and code Playground
by vijayweb
HTML
<p>Clicked: <strong>One</strong><br/><strong>Two</strong></p>
JavaScript
function elementPath(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(".").toLowerCase();
}
$(document).ready(function() {
$(document).click(function(e) {
e.stopPropagation();
window.alert(elementPath(e.target));
});
});