Home > Java Script > Today’s Learning: binding more than one events in jquery

Today’s Learning: binding more than one events in jquery

November 21, 2012 Leave a comment Go to comments

To call a custom event handler when an event fires, we can use “.bind()” jquery method as described below :

$(‘#foo’).bind(‘click’, function(){
//do something on click event fire
});

To bind more than one events to one element, we can include each event in “.bind()” method separated by space :

$(‘#foo’).bind(‘click mouseover keyup …’, function(){
//do something on event fire
});

To bind multiple event handlers to one element (As of jQuery 1.4) :

$(‘#foo’).bind({
focusout: function() {
// do something on focusout
},
mouseover: function() {
// do something on mouseover
},
click: function() {
// do something on click
}
});

Advertisements
Categories: Java Script Tags: ,
  1. No comments yet.
  1. No trackbacks yet.

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

%d bloggers like this: