Question: Suppose I have this HTML:

```
<div class="SomeParent" id="BlueParent">
  <div>
     <div class="Test">test</div>
  <div>
</div>

```

The div of class `Test` is actually deeply nested in the `SomeParent` container. What's the **fastest** way to get the id of the `SomeParent` class of which Test is a descendant. Is the `.parent()` the best way to do it?

Thanks for your suggestions.

Answer: 
You can try:

```
$('div.SomeParent').has('div.Test').attr('id');

```

**[DEMO](http://jsfiddle.net/PGqR4/)**

Instead of parent you can use **[`.has()`](http://api.jquery.com/has/)**.

Another choice is **[`closest()`](http://api.jquery.com/closest/)**:

```
$('.Test').closest('.SomeParent').attr('id')

```

**[DEMO](http://jsfiddle.net/PGqR4/3/)**
You could use parents() rather than parent() to specify the class of the parent element that you are searching for within the DOM tree of parents.

```
$(".Test").parents(".SomeParent").attr("id")

```