I have a table with data in:
<td> item </td><td> order code </td><td> price </td>
I’m processing the table with jQuery which needs to find the order code:
$.each($('.productList tbody tr'), function() {
var orderCode = $(this).find('td:eq(1)').html().trim();
// do stuff
});
If there are no products, the table shows a message:
<td colspan="3"> There are no products to display </td>
The above row causes the jQuery function to bomb out. What’s the most robust way to use a conditional selector to ignore the “no products” row? Is there a selector for colspan="1" or colspan is not set or whatever it would need to be?
Don’t refine your selector, it won’t scale well because jQuery will have to evaluate every child element. Avoid the error instead…