Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery remove empty td cells

Tags:

jquery

I need to remove all empty td cells, can I do this with jQuery.

<td></td>

if(td == empty){
$("td").remove();
}

I'm not sure how to write what I'm trying to do.

like image 644
Blynn Avatar asked Apr 12 '13 16:04

Blynn


3 Answers

This is the way to go: {pseudo class empty}

$("td:empty").remove();
like image 119
A. Wolff Avatar answered Nov 15 '22 14:11

A. Wolff


To remove all empty td

$('td').each(function() {
    if ($(this).html() == '') {
        $(this).remove();
    }
  }
like image 27
Mohammad Adil Avatar answered Nov 15 '22 13:11

Mohammad Adil


You can use .each()

$("td").each(function() {
    if ($(this).html() == "") {
        $(this).remove();
    }
}
like image 23
tymeJV Avatar answered Nov 15 '22 12:11

tymeJV