Have you tried doing $('#filter option:selected').text();

There was a similar problem with using [EMAIL PROTECTED] before. No one
explained why it wasn't working though

Kush

-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On
Behalf Of Mungbeans
Sent: Tuesday, 19 December 2006 10:41 AM
To: discuss@jquery.com
Subject: Re: [jQuery] Getting the TEXT of an option tag, not the value.




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
discuss@jquery.com
http://jquery.com/discuss/


_______________________________________________
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/

Reply via email to