Bind multiple events to jQuery 'live' method

From jQuery 1.7, "on" function is what you're looking for :

$("a").on({
    click: function() {
        // do something on click
    },
    mouseenter: function() {
       // do something on mouseenter
    },
    mouseleave: function() {
         // do something on mouseleave
    }
});

As of jQuery 1.4.1 .live() can accept multiple, space-separated events, similar to the functionality provided in .bind(). For example, we can "live bind" the mouseover and mouseout events at the same time like so:

$('.hoverme').live('mouseover mouseout', function(event) {
  if (event.type == 'mouseover') {
    // do something on mouseover
  } else {
    // do something on mouseout
  }
});

In jQuery 1.7 there is an API that allow you to do it easily...

$(".myClass").on({
    click: function(){
         alert("You click on me!");
    },
    mouseenter: function(){
         alert("Do you want click on me?");
    }
});

In my opinion this method is completely efficient and gathering all abilities that you can use in element's event....

Take a look at this page .on() [ jQuery 1.7 API ]


Try in this way:

("#button").bind("click keyup", function(){

// your code goes here

}) 

Tags:

Jquery