Problem using jQuery change function on a select element
I am using a simple select element. On selecting a option in the select menu, I want to use jQuery's pos开发者_JAVA百科t method to update the div.
<select class="article">
<option value="title1">title1</option>
<option value="title2">title2</option>
<option value="title3">title3</option>
</select>
I want to bind the change event to the select element.
$(document).ready(function() {
$(".article").change(function() {
var src = $(this).val();
alert(src);
});
});
This does not work. I don't see the alert box on changing the select box.
I appreciate any help.
It does work fine
Working demo
This should work fine, have you included jQuery files. Please check that jQuery is included properly.
$(document).ready(function() {
alert('hello');
});
This should give an alert, in case this does not, then jQuery is not working properly.
$('select.foo option:selected').val(); // get the value from a dropdown select
More about the subject;
http://api.jquery.com/val/
http://api.jquery.com/selected-selector/
jQuery - setting the selected value of a select control via its text description
精彩评论