JSFiddle - React, Tailwind, and code Playground

HTML

<div id="tableContainer" class="divClass">
    <div id="tableContainer" class="divClass">
        <table id="myTable" border=2>
            <tr>
                <td> row 1 and cell 1        </td>
                <td>row 1 and cell 2        </td>
                <td>
                    <div id="cellDiv"> row 1 and cell 3 </div>
                </td>
            </tr>
        </table>
    </div>
</div>

CSS

.divClass{
    background-color:#ccc;
}
.oneLineCode{
    background-color:#ccc;
    
    font-weight:bold;
    border:2px solid #a1a1a1;
    padding:10px 10px; 
}

JavaScript

var $cellDiv = $("#cellDiv");
 
//Getting First Parent by tag of cellDiv
 alert("First Parent by tag :"+$(cellDiv).parent().closest("DIV").attr('id') );

//Getting First Parent by id of cellDiv
alert("First Parent by id :"+$(cellDiv).closest("#tableContainer").attr('id') );

//Getting First Parent by class and then remove css 
var $tableContainerDiv = $(cellDiv).closest(".divClass");
alert("First Parent by class :"+$tableContainerDiv.id +" Now removing css");
$tableContainerDiv.removeClass('divClass');


//get all parents by tag name of cellDiv
alert("no. of parent divs of cellDiv:"+$("#cellDiv").parents("DIV").length);