I have an HTML dropdown. I want to fire an event whenever the selection changes in any way.
I tried registering a click
event but this didn't work when multi-selecting (either by dragging the mouse or holding down shift + down arrow).
So basically, how can I fire an event on any selection change?
I have an HTML dropdown. I want to fire an event whenever the selection changes in any way.
I tried registering a click
event but this didn't work when multi-selecting (either by dragging the mouse or holding down shift + down arrow).
So basically, how can I fire an event on any selection change?
Share Improve this question edited Apr 16, 2024 at 0:55 informatik01 16.4k11 gold badges78 silver badges108 bronze badges asked Mar 30, 2011 at 20:34 johnjohn 2,8536 gold badges24 silver badges14 bronze badges 1- 1 Example: jsfiddle.net/D92z7 – jAndy Commented Mar 30, 2011 at 20:38
3 Answers
Reset to default 12Try using the onchange
event.
$('#mySelect').change(function(){
alert($(this).val());
});
Would .change() do the trick?
http://api.jquery.com/change/
Certainly there seems to be a working demo of a multi-select box on that page...
jquery 1.4: $("#mySelector").change(myChangeEvent);
before: $("#mySelector").bind("change", myChangeEvent);
function myChangeEvent(e){
}