Nicholas Murray
Nicholas Murray

Reputation: 13529

jQuery verification of select list contents

Is it possible using jQuery to verify if the following HTML select list contains any items?

HTML Select List of Countries which will initially be empty and may remain so unless populated.

<select size="5" name="Country" multiple="multiple" id="Country"> 
</select>

Upvotes: 0

Views: 257

Answers (4)

Mark
Mark

Reputation: 10206

$("#Country option").length > 0

Upvotes: 0

Jordan Ryan Moore
Jordan Ryan Moore

Reputation: 6887

if (0 == $('#Country option').length) {
    // no options
} else {
    // options!
}

Upvotes: 0

Josh Pearce
Josh Pearce

Reputation: 3455

if($('#Country').children().length > 0) {
    ...
}

Upvotes: 1

Joel
Joel

Reputation: 19368

This will return true when there are items in the select.

alert($("#Country").children().length > 0);

Upvotes: 2

Related Questions