This works: 

$(this).find("option:selected").parent().attr("label")

I believe :selected reads the property then the attribute, whereas @selected
reads just the attribute.

See:
http://www.nabble.com/Getting-the-TEXT-of-an-option-tag%2C-not-the-value.-tf1919282.html#a7939730

~Philip



George Adamson wrote:
> 
> I hope I've understood this correctly.
> Perhaps try something along the lines of this in the function (not
> tested)...
> 
>    var myOptGrpLabel =
> $(this).find("[EMAIL PROTECTED]").parents("OPTGROUP").attr("label");
>    /* ... do something with myOptGrpLabel... */
> 
> The parents("OPTGROUP") could be overkill, maybe just .parent() is enough
> if you're sure the option elements are in an optgroup.
> 
> George
> 
> 
> 
> GreyCells wrote:
>> 
>> I'd like to be able to display the optgroup label attribute value after a
>> select list is changed. This is what I have so far, but I think I'm
>> heading down the wrong track, because a) I want the optgroup label value,
>> not the selected option value and b) I don't want to keep appending if
>> the user changes the selection more than once...
>> 
>> $(document).ready(function() {
>>   $('#MySelect').change( function() { 
>>              $('#MySelect').after('('+$('#MySelect').val()+')'); 
>>   } ) ;
>> });
>> 
>> Any help would be appreciated :)
>> 
>> ~Philip
>> 
> 
> 

-- 
View this message in context: 
http://www.nabble.com/Getting-the-optgroup-for-a-select-option-tf3023854.html#a8401983
Sent from the JQuery mailing list archive at Nabble.com.


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

Reply via email to