slandau
slandau

Reputation: 24052

Check for null cells in HTML Table

So I have this div on my page:

<div id="valueTableBTS"></div>

This div gets filled with an html table dynamically. What I want to be able to do in JQuery is to check if this table has any empty cells, so I know if I need to keep calling my other method to fill it with any newly grabbed values.

How would I do that?

Upvotes: 2

Views: 3393

Answers (3)

DA.
DA.

Reputation: 40673

After the table is inserted, you could iterate through the TDs:

$('.yourTable td').each(function(){

    if ($(this).text=""){
        //it's blank
    }
  })

Upvotes: 0

jAndy
jAndy

Reputation: 235972

If I get you right, this should do it:

if( $('#valueTableBTS tbody').find('td:empty').length ) {
    // at least one <td> is empty
}

Demo: http://jsfiddle.net/p53Y8/


The :emptyhelp selector will find nodes which have no children (including text nodes).

Upvotes: 1

Grim...
Grim...

Reputation: 16953

if ($("#valueTableBTS").children(".cellClass").length == 0) {
    //blah
}

Upvotes: 0

Related Questions