parentsUntil function in jQuery

Add suffiecient HTML in your html support code file:parents Until function in jQuery
<div class="target-parent" style="width:500px;">test(great-grandparent)
      <div>(direct parent)

And then add the following script to change color until the specific parent does exist:
  $("span").parentsUntil(".target-parent").css({"color": "red"});
Now you can see your output like this:

add variants in Shopifyexpoundsofttechsolution

parents Until function in jQuery