I would like to print the selected values of all selects using jQuery. I did it like this, but I feel that there is a nicer way to write the same. Am I right ?
$("select").each(function() {
alert(this.options[this.selectedIndex].value);
});
I would like to print the selected values of all selects using jQuery. I did it like this, but I feel that there is a nicer way to write the same. Am I right ?
$("select").each(function() {
alert(this.options[this.selectedIndex].value);
});
Yes.
alert($(this).val());
jQuery's val function will return the value of the selected option from a <select> element.