Marcus Leon
Marcus Leon

Reputation: 56669

JQuery - determine if ALL multiple select box items are selected?

What is the easiest way to determine if ALL items in a multiple HTML select box are selected?

Upvotes: 9

Views: 6644

Answers (2)

hunter
hunter

Reputation: 63512

check if the number of not selected is zero and if there are at least 1 option

var all = $("select :not(:selected)").length == 0 && $("select options").length > 0;

Upvotes: 1

Nick Craver
Nick Craver

Reputation: 630379

You can check the .length of :not() :selected <option> elements, for example:

var allSelected = $("#selectID option:not(:selected)").length == 0;

Upvotes: 19

Related Questions