Matthew Moon Matthew Moon - 1 year ago 125
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 Source

Try

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