JSFiddle - React, Tailwind, and code Playground

by Xeon06

HTML

<div id="bar">
    <div>
        <div id="foo"></div>
    </div>
</div>

JavaScript

(function($) {
    $.fn.parentNth = function(n) {
        var el = $(this);
        for(var i = 0; i < n; i++)
            el = el.parent();
        
        return el;
    };
})(jQuery);

alert($("#foo").parentNth(2).attr("id"));