closest

.closest( selector )

selector

find the closest parent element matches with the selector.

<div id="c1" class="container"> <span id="sp1" class="left"> <div id="d1"></div> <div id="c2" class="container"></div> </span> </div> <script> qsi("d1").closest(".container").id; //c1 </script>