Using .hide() instead of .remove()
<p>The output should be like in this <a href="http://jsfiddle.net/SpB3m/3/" rel="nofollow">demo</a>. The problem is that I need to use .hide() instead of .remove(). Does anyone have any idea to solve it?</p>

<pre><code>$('td').parents('tr:contains(John)').remove();

$('tr').parents('tbody').not(':has(td)').after('&lt;tr&gt;&lt;td&gt; Perfect!! &lt;/td&gt; &lt;/tr&gt;');
</code></pre>

<p>How can i resolve the same problem where <code>.hide()</code> is in the place of <code>.remove()</code>?</p>

<hr>

<pre><code>&lt;table&gt;    
    &lt;tr&gt;
        &lt;th&gt;Name&lt;/th&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
        &lt;td&gt;John&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
        &lt;td&gt;Max&lt;/td&gt;
    &lt;/tr&gt;
&lt;/table&gt;

    &lt;/br&gt;&lt;/br&gt;

&lt;table&gt;
    &lt;tr&gt;
        &lt;th&gt;Name&lt;/th&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
        &lt;td&gt;John&lt;/td&gt;
    &lt;/tr&gt;    
&lt;/table&gt;
</code></pre>
