Reputation: 585
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
Reputation: 1487
You can use the :empty
selector:
$('#MyGrid tbody:empty').append('<tr><td><a href="#" >' + htmlString.ID+ '</a></td></tr>');
Upvotes: 0
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