.closest() in jQuery

It helps to returns the first ancestor of the selected element.

.closest()

// To add border and text color of “ul” nearby “span”.

<ul>style will affect here
  <li>
    <span>contents</span>
  </li>
</ul>

$(document).ready(function(){
    $(“span”).closest(“ul”).css({“color”:”yellow”,”border”:”2px solid yellow”});
});