JSFiddle - React, Tailwind, and code Playground

HTML

<div class="target">
    <span>Nested span (parent has class 'target')</span>
</div>

JavaScript

document.addEventListener("click", function (e) {
    var target = e.target;
    
    while (target && target.parentNode !== document) {
        target = target.parentNode;
        if (!target) { return; } // If element doesn't exist

        if (target.classList.contains('target')){
            // do stuff
            console.log(e.target);
        }
    }
});