JSFiddle - React, Tailwind, and code Playground
HTML
<div>
<div>
<p>foo</p>
</div>
</div>
JavaScript
var mapPath = function($el) {
$el = $($el); // just in case?
var myPath = $el[0].tagName;
while (true)
{
$el = $el.parent();
var curNode = $el[0].tagName;
myPath = curNode + ' ' + myPath;
}
return myPath;
}
$(function() {
alert(mapPath($('p')));
});