jQuery – event handler for dropdown change

There are multiple ways of handling events in jQuery using callback methods. The callback method can be written inline or it can be written as a separate function and called from the bind call. Here’s what I mean.

$( "#id_dropdown" ).bind("change", function(e) {
		alert ("Dropdown value changed");
		alert(e.val());
	});

OR

$( "#id_dropdown" ).bind("change", handleDropdownChange);
var handleDropdownChange = function() {
	alert ("Dropdown value changed");
	var $dropdown = $( this );
	alert($dropdown.val());
};
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s