title: jQuery .hasClass, .closest() and $(this)
body: <p>I'm trying to highlight the parent <code>tr</code> of a table, if a children <code>td &gt; p</code> has a certain class. I have the following:</p>
  
  <pre><code>$(document).ready(function(){
      var $target = $('.flag-wrapper p').closest("tr");
      var $element = $('.flag-wrapper p').hasClass("selector-on");
  
      if ( $element ) {
          $target.addClass("marked-row");
      } else {
          // whatsoever
      }
  });
  </code></pre>
  
  <p><a href="http://jsfiddle.net/cZJca/1/" rel="nofollow">http://jsfiddle.net/cZJca/1/</a></p>
  
  <p>Now my problem is that I can't target just the current <strong>tr</strong>. I've tried using $(this) but as far as I can tell it won't work inside the if statement.</p>
  
  <p>Any insights on how should I proceed with this would be much appreciated. Also, I guess it would be easier to work with a .click() event but I have to check this .hasClass() on page load instead of user action.</p>