title: Jquery remove closest tr fail
body: <p>I want to do the manipulation to remove the closest table when certain wording is exist at html.</p>
  
  <p>I cannot assume the span class will exist there, because the html is retrieved from other side, they may change it by adding, removing any class anytime.</p>
  
  <p>It need to be done on page load, not when the class/id event inside is clicked.</p>
  
  <p>Kinda challenging. Any idea how to achieve this?</p>
  
  <p>On page load, </p>
  
  <p>jquery to detect whether "Hello how are you" is exist in page.</p>
  
  <pre><code>If exist
      remove the whole td or tr or table for this particular.
  else
      do nothing.
  end
  </code></pre>
  
  <p>Code as below:</p>
  
  <pre><code>function replaceText() 
  {
  
      var debug;
      debug= "";
  
  
      $("*").each(function() { 
          if($(this).children().length==0) 
      { 
  //            $(this).text($(this).text().replace('Hello how are you', 'yohoo')); 
  
          debug= debug + $(this).val() + "&lt;br&gt;";
  
          if($(this).val()=="Hello how are you")
          {
              $(this).closest('table').remove();
          }
  
          } 
      });
  
  //alert(debug);
  
  }
  
  
  &lt;div&gt;
  
  
  &lt;table&gt;
  
      &lt;tr&gt;
  
      &lt;td colspan="2"&gt;
  
  
          &lt;div&gt;
  
  
              &lt;table&gt;
  
              &lt;tr&gt;
  
              &lt;td &gt;&lt;span class="myclass"&gt;Hello how are you&lt;/span&gt;&lt;/td&gt;
  
              &lt;td&gt;&lt;a href="testing.php"&gt;&lt;/a&gt;&lt;/td&gt;
  
              &lt;/tr&gt;
  
              &lt;/table&gt;
  
  
          &lt;/div&gt;
  
  
      &lt;/td&gt;
  
      &lt;/tr&gt;
  
  
      &lt;tr colspan="2"&gt;
          &lt;table&gt;
  
          &lt;tr&gt;
  
          &lt;td&gt;&lt;b&gt;want to remove this&lt;/b&gt;&lt;/td&gt;
  
          &lt;/tr&gt;
  
          &lt;/table&gt;
      &lt;/tr&gt;
  
      &lt;tr&gt;
          &lt;td&gt;other content 1&lt;/td&gt;
          &lt;td&gt;other content 2&lt;/td&gt;
      &lt;/tr&gt;
  
  &lt;/table&gt;
  
  &lt;/div&gt;
  </code></pre>