Jump to content

Get the nearest <div> parent containing an child with class "sample"? jQuery if possible


pstein

Recommended Posts

Assume I have the following simplified code:

<div>  "1"
<div>   "2"
<p>
<div>   "3"
<span>
<img class="sample">...</img>
</span>
</div>
</p>
</div>
</div>

Now I want to refer to innermost parent <div> element which contains a child element with class "sample".
Here it is an <img> element in other cases it could be a <figure> or whatever.
As target <div> element I would like to get the <div> labelled here with "3".

How can I achieve this?

If possible as jQuery statement.

Thank you

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...