This has been a hot topic today. Try using the :selected selector
instead of the attribute selector.

$('#mySelect option:selected').text();

--
Brandon Aaron

On 12/18/06, Mungbeans <[EMAIL PROTECTED]> wrote:
>
>
>
> Andy Matthews wrote:
> >
> >
> > A more generic approach:
> >
> > $('#mySelect [EMAIL PROTECTED]').text();
> >
> >
>
> This isn't working for me.  I have a select box that looks like this before
> a selection is made:
>
> <select name="filter" id="filter" class="selectbox" size="1">
>         <option value="0" selected="selected">--</option>
>         <option value="2">A:Option 2</option>
>         <option value="1">B:Option 1</option>
> </select>
>
> Here is my code to get the text inside the selected option (after change):
>
> Assuming I selected the third in the list (val=1)
>
> var id = $("#filter").val();    //correctly returns 1 as the value
> if (id != 0 ) {
>   var str = $('#filter [EMAIL PROTECTED]').text();    //incorrectly returns
> "--" as the text
> }
>
> option:eq(1)
> This returns the second option - using index 1 not value 1 - which is what I
> am after.
>
>
> --
> View this message in context: 
> http://www.nabble.com/Getting-the-TEXT-of-an-option-tag%2C-not-the-value.-tf1919282.html#a7938927
> Sent from the JQuery mailing list archive at Nabble.com.
>
>
> _______________________________________________
> jQuery mailing list
> [email protected]
> http://jquery.com/discuss/
>

_______________________________________________
jQuery mailing list
[email protected]
http://jquery.com/discuss/

Reply via email to