CLiown
CLiown

Reputation: 13843

Add class to DIV with TD Wrapping

Im trying to add a class to a TD which contains a DIV.

HTML:

<td>
  <div class="report">
    Some HTML
  </div>
</td>

My jQuery:

$('.report').prev().addClass('wrapper');

What am I doing wrong?

Upvotes: 0

Views: 125

Answers (2)

Exelian
Exelian

Reputation: 5888

.prev() searches only among siblings of the node, ie. nodes that reside on the same level of the DOM tree. The function you're looking for is .parent().

Upvotes: 2

Dheeraj Kumar
Dheeraj Kumar

Reputation: 1008

$('.report').parent().addClass('wrapper');

Parent, not Prev :)

Upvotes: 4

Related Questions