Reputation: 55
If the input is a select type, I want to get the text of the selected option, not the value.
This is what I have so far:
$('.encodageField').live('change', function(){
if( $(this).is('select') ) {
val = $($(this) + 'option:selected').text();
alert (val);
}else{
val = $(this).val;
alert (val);
}
save_answer($(this));
});
So I need the text of $(this) the changed select. How do I use 'this' in combination with 'option:selected' as a selector.
Upvotes: 1
Views: 145
Reputation: 35213
I think this should be equivalent to Leigh's answer
$(this).find('option:selected').text();
Upvotes: 0