This evaluates to true if it already exists:
$("#yourSelect option[value='yourValue']").length > 0;
ID : 20383
viewed : 13
93
This evaluates to true if it already exists:
$("#yourSelect option[value='yourValue']").length > 0;
90
Another way using jQuery:
var exists = false; $('#yourSelect option').each(function(){ if (this.value == yourValue) { exists = true; } });
74
if ( $("#your_select_id option[value=<enter_value_here>]").length == 0 ){ alert("option doesn't exist!"); }
70
var exists = $("#yourSelect option") .filter(function (i, o) { return o.value === yourValue; }) .length > 0;
This has the advantage of automatically escaping the value for you, which makes random quotes in the text much easier to deal with.
54
Although most of other answers worked for me I used .find():
if ($("#yourSelect").find('option[value="value"]').length === 0){ ... }