michael
michael

Reputation: 585

how to test whether grid is empty or not in jquery

i have a grid and adding elements to is in jquery like below:

$('#MyGrid tbody').append('<tr><td><a href="#" >' + htmlString.ID+ '</a></td></tr>');

before that i need to test whether this MYgrid is empty or not. how to do that with jquery.

thanks,

michaeld

Upvotes: 0

Views: 4496

Answers (2)

Jayne Mast
Jayne Mast

Reputation: 1487

You can use the :empty selector:

$('#MyGrid tbody:empty').append('<tr><td><a href="#" >' + htmlString.ID+ '</a></td></tr>');

Upvotes: 0

karim79
karim79

Reputation: 342665

Can you not just count the rows, and if there are non, assume that your grid is empty?

if(!$('#MyGrid tr').length) {
    // grid is empty
}

Upvotes: 1

Related Questions