I'm trying to use jQuery to check for the existence of an <option>
that contains a particular string of text. My attempts so far are not working as I expect. Here's the HTML:
<select>
<option value="13">General</option>
<option value="3">Innovation</option>
<option value="8">Marketing</option>
<option value="9">Operations</option>
<option value="11">Research</option>
</select>
Here's the script:
var topicSelect = $("select");
var haveTopic = topicSelect.val("Not Here");
alert(haveTopic);
I'm expecting the alert to show "undefined" however it seems to be giving back the select
object. Is there a way I can check for the existence of an option without looping through every one?
Clarifications:
- string of text needs to be matched, not value
- looking for an exact, case sensitive match
- can return true/false or undefined