JSFiddle - React, Tailwind, and code Playground

by TrueBlueAussie

HTML

<div class="level0">Level 0
    <div class="level1">Level 1
        <div class="level2">
            <div class="level3">Sometext</div>
        </div>
        <div class="level2">
            <div class="level3">Sometext</div>
        </div>
        <div class="level2">
            <div class="level3">Sometext</div>
        </div>....</div>
</div>

CSS

div {
    padding: 5px;
    border: 1px solid green;
}

JavaScript

(function ($) {
    $.fn.commonParents = function (){
        var cachedThis = this;
        return cachedThis.first().parents().filter(function () {
            return $(this).find(cachedThis).length === cachedThis.length;
        });
    };
    $.fn.commonParent = function (){
        return $(this).commonParents().first();
    };
})(jQuery);

var matches = $(':not(:has(*))').filter(function () {
    return $(this).text() == "Sometext";
});

matches.commonParent().css('border-color','red');