Billy Billy - 7 months ago 17
Javascript Question

How can I check whether a option already exist in select by JQuery

How can I check whether a option already exist in select by JQuery?

I want to dynamically add options into select and so I need to check whether the option is already exist to prevent duplication.

Answer

This evaluates to true if it already exists:

$("#yourSelect option[value='yourValue']").length > 0;
Comments