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.
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.
Does not work, you have to do this:
This evaluates to true if it already exists:
I had a similar issue. Rather than run the search through the dom every time though the loop for the select control I saved the jquery select element in a variable and did this:
This has the advantage of automatically escaping the value for you, which makes random quotes in the text much easier to deal with.
Another way using jQuery: