I’m trying to replace all my empty select boxes with a text message but it’s not working. Here’s my jQuery:
var s = $("table.preference select option");
if(s.length == 0){
s.parents("td").html("No more preferences to add!");
}
I’ve also tried:
$("table.preference select option").each(function(){
if($(this).length == 0){
$(this).parents("td").html("No more preferences to add!");
}
});
But neither works. I have two select tags in two different tables – I need the jQuery to find any empty select box and replace its table cell with a text message. Does anybody know where I’m going wrong?
Your first approach will not work if you have at least 1 option-element in one of all select-elements inside the table.
Solution without using $.each():