March 23, 2011

(jQuery) How to delete all cell from this table?

Question by l2aelba

<table class="Table">
    <thead class="thead">
        <tr class="tr">
            <th class="th header">Done</th>
            <th class="th header">None</th>
            <th class="th header">None</th>
            <th class="th header">Done</th>
            <th class="th header">None</th>

            <tr>
                <td>info</td>
                <td>info</td>
                <td>info</td>
                <td>info</td>
                <td>info</td>
            </tr>
        </tr>
    </thead>
</table>

I want to delete all “None”s cell and all “info” of cells

http://jsfiddle.net/D6e4H/

Any idea ? Thanks

Answer by Furqan

use this

    $(".th:contains('None')") .remove();
    $("td:contains('info')") .remove();

Your jsFiddle has been updated.

Answer by Starx

I think you are looking for this

$("th:contains('None')").each(function(index,value) {
    //Grab all the "None" th and their indexes
    $("tr td:nth-child("+$(this).index()+")").remove();
    //remove the td with the same indexes on the next tr
    $(this).remove();
    // now also remove the "None" th
});

Here is your Solution

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!