April 16, 2012

Using .hide() instead of .remove()

Question by ptthttp

The output should be like in this demo. The problem is that I need to use .hide() instead of .remove(). Does anyone have any idea to solve it?

$('td').parents('tr:contains(John)').remove();

$('tr').parents('tbody').not(':has(td)').after('<tr><td> Perfect!! </td> </tr>');

How can i resolve the same problem where .hide() is in the place of .remove()?


<table>    
    <tr>
        <th>Name</th>
    </tr>
    <tr>
        <td>John</td>
    </tr>
    <tr>
        <td>Max</td>
    </tr>
</table>

    </br></br>

<table>
    <tr>
        <th>Name</th>
    </tr>
    <tr>
        <td>John</td>
    </tr>    
</table>

Answer by Starx

You can use .hide() instead of .remove() there is no problem on it.

$('td').parents('tr:contains(John)').hide();

See How?

Author: Nabin Nepal (Starx)

Hello, I am Nabin Nepal and you can call me Starx. This is my blog where write about my life and my involvements. I am a Software Developer, A Cyclist and a Realist. I hope you will find my blog interesting. Follow me on Google+

...

Please fill the form - I will response as fast as I can!