jQuery bind() Method

jQuery bind() method attach one or more event handlers for selected elements. And when the bind event occurs, specified function will execute.

The bind() method was deprecated in jQuery 3.0. Use the on() method instead of this.

Syntax

This syntax represents to the bind event

$(selector).bind(eventType, eventData, function)
Parameter Type Description
eventType String Required. Specifies one or more DOM event types (such as "click" or "dblclick" or custom event names) to attach to the elements.
eventData Object Optional. Specifies additional data that will be passed to the event handler.
function Function Required. Specifies the function to execute when the event is occurs.

Examples

$(document).ready(function(){
  $("button").bind("click",function(){
    $("p").fadeTo("slow", 0.20);
  });
});

Run it...   »


This example represent how to attach multiple events to an element.

$(document).ready(function(){
  $("button").bind("mouseover mouseout",function(){
    $("p").fadeToggle(1500);
  });
});

Run it...   »


This example represent how to pass data along with function.

$(document).ready(function(){
  $("button").bind("click", {"text": "You clicked on button."}, function(e){
    $("p").fadeToggle(1500);
    alert(e.data.text);
  });
});

Run it...   »