JSFiddle - React, Tailwind, and code Playground
HTML
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js"></script>
<div id="foo">
<article>
<div>
<p>you found me</p>
</div>
</article>
<div>
JavaScript
$(document).ready(function () {
var path = '';
$('#foo').on('click', '*', function (e) {
path = $(this).prop("tagName").toLowerCase();
$(this).parents().each(function () {
let id = $(this).attr('id');
path = $(this).prop("tagName").toLowerCase() + (typeof id != 'undefined' ? '#'+id : '') + ' > ' + path;
});
alert(path);
e.stopPropagation();
});
});