JQuery How do I select EXACTLY the Text I need from dropdown options?
<p><code>:contains</code> just isnt doing it for me here. Its too coarse. and I cant seem to figure out the right way to get it.</p>

<p>(.js fiddle below)</p>

<pre><code>$(function() {
    $('#my_button').click(function() {
        var cookieVal = "ab"; //This is what I want to find
        var select = "combo0";

        var optionThatMatchesCookie = $("#" + select + " option:contains('" + cookieVal + "')").val();
        alert(optionThatMatchesCookie); //returns the wrong entry! (returns 'cabd' not 'ab')

        if (typeof(optionThatMatchesCookie) != "undefined") {
            //now put that in the combobox
            $('#' + select).val(optionThatMatchesCookie);
        }
    });
});

&lt;select class="inputfield" id="combo0" name="jobType"&gt;
    &lt;option selected="selected"&gt;-select-&lt;/option&gt;
    &lt;option id="1"&gt;sssssssssss&lt;/option&gt;
    &lt;option id="18"&gt;fffffffffff&lt;/option&gt;
    &lt;option id="47"&gt;cabd&lt;/option&gt;
    &lt;option id="3"&gt;LPN/LVN&lt;/option&gt;
    &lt;option id="22"&gt;bbbbb&lt;/option&gt;
    &lt;option id="17"&gt;hhhhhhhhhh&lt;/option&gt;
    &lt;option id="15"&gt;aaaaaaa&lt;/option&gt;
    &lt;option id="16"&gt;zzzzzzzzzzzzzzz&lt;/option&gt;
    &lt;option id="5"&gt;ab&lt;/option&gt;
    &lt;option id="44"&gt;YYYYYYYYY&lt;/option&gt;
    &lt;option id="19"&gt;XXXXXX&lt;/option&gt;
&lt;/select&gt;
&lt;input type="button" id="my_button" value="test me"/&gt;
</code></pre>

<p><a href="http://jsfiddle.net/KGabbert/mCDer/3/" rel="nofollow">http://jsfiddle.net/KGabbert/mCDer/3/</a></p>
