I've tried this, and it works just fine with jQuery 1.1.1

$(document).ready(function(){
   console.log($('#mySelect :selected').text());
   $('#mySelect').change(function(){
       console.log($(this).find(':selected').text());
   });
});

<select id="mySelect">
   <option value="1">one</option>
   <option value="2" selected="selected">two</option>
   <option value="3">three</option>
</select>

Regards Alexis,


On 2/16/07, Alexis Bellido <[EMAIL PROTECTED]> wrote:



Mungbeans wrote:
>
> Ah.  This is getting closer.  Rather bizarrely, it returns the text for
> both the original selection AND the new selection,
>
> Eg "--B:Option 1"
>
> But at least I can just chop off the first two characters - near enough
is
> good enough.
>

Chopping off  the first characters doesn't work all times. For example, if
we have:

<select id="mySelect">
  <option value="1">one</option>
  <option value="2" selected="selected">two</option>
  <option value="3">three</option>
</select>

and you try:

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

you'll get:
onetwo if you select option 1
two if you select option 2
twothree if you select option 3

I'll try using each() and comparing val() as Sean suggested.

Any other ideas?

Alexis Bellido
--
View this message in context:
http://www.nabble.com/Getting-the-TEXT-of-an-option-tag%2C-not-the-value.-tf1919282.html#a8999078
Sent from the JQuery mailing list archive at Nabble.com.


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




--
Joan Piedra || Frontend webdeveloper
http://joanpiedra.com/
_______________________________________________
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/

Reply via email to