Question: I have the following HTML structure, I want to add a class to the last `<div>` which contains the `<p>` tag but only when it exists. 

```
<div id="view">
  <div class="login">
  </div>
  <div>
    <p>Add a class to this parent DIV</p>
  </div>
</div>

```

Any suggestions?

Answer: 
Simple snippet:

```
if($('#view div:last p').​​​​​​​​​​​length)
    $('#view div:last').addClass('myClass');​​​​​​​​​​​

```
Will get all the divs that has a p tag

```
p = $('#view div p');
if (p.length) {
  $(p[p.length - 1]).addClass("largerText");
}​

```

Here is the [fiddle](http://jsfiddle.net/bLLWg/2/)