The following code works:
$(\"#select-id\").change(function(){
var cur_value = $(\'#select-id option:selected\').text();
. . .
});
How
var cur_value = $(this).find('option:selected').text();
Since option
is likely to be immediate child of select
you can also use:
var cur_value = $(this).children('option:selected').text();
http://api.jquery.com/find/
This should work:
$(this).find('option:selected').text();
You can use find
to look for the selected option that is a descendant of the node(s) pointed to by the current jQuery object:
var cur_value = $(this).find('option:selected').text();
Since this is likely an immediate child, I would actually suggest using .children
instead:
var cur_value = $(this).children('option:selected').text();