How can I find a specific ancestor DOM element using jQuery?

$0
=
$0
+
$0
No specific Bitcoin Bounty has been announced by author. Still, anyone could send Bitcoin Tips to those who provide a good answer.
0

I need to find a specific ancestor element (parent, grandparent, etc) which MAY be located FEW LEVELS above the given (child / descendant) element in the HTML DOM tree. The specific element I am looking for is marked with a special CLASS, i.e. .

> ... class = "parent" ...

I'd like to use jQuery to locate that ancestor element starting from one of its descendant elements. Thanks!

1 Answer - total earned - 0.5 mBTC ($0.13 USD)

1
=
2
=
$0.13
2 tips with total amount of 0.5 mBTC($0.13 USD) have been sent by Non-Registered User

I've found an answer.

Need to use function ".closest". For example:

<div class="parent">
   <div>
      <div class="child"></div>
   </div>
</div>
<script> var oParent =  $('.child').closest('.parent'); </script>
SEND BITCOIN TIPS

Thank You for your help!

Good answer

Привет из России :)

0

Post Answer


Top 3 Tippers
Recent Tips

Will Bitcoin Tipping become a new Internet Culture?


Please share our story! THANK YOU!