Matthew Moon Matthew Moon - 6 months ago 21
jQuery Question

Select all un-selected boxes in multi-selector

How do I get all the unchecked boxes in a multi-selector? To get the selected boxes I have:

$("#studentsWeek1Room21 option:selected").each(function(){
selectedValues.push($(this).val());
});


Attempting to get the unchecked ones:

$("#studentsWeek1Room21 option:not(selected)").each(function(){
unselectedValues.push($(this).val());
});

Answer

Try

$("#studentsWeek1Room21 option").not(":selected").each(function(){
    selectedValues.push($(this).val());
});