jQuery Event - bind() Method

Example

Hide or show the p element when the mouse is clicked:

$("button").bind("click",function(){
  $("p").slideToggle();
});

Try It Yourself

Definition and Usage

The bind() method adds one or more event handlers to the selected element and specifies the function to be executed when the event occurs.

Binding Events and Functions to Elements

Specifies one or more event handlers to be added to the selected element, as well as the function to be executed when the event occurs.

$(selector).bind(event,data,function)

Try It Yourself

Parameter Description
event

Required. Specifies one or more events to be added to the element.

Separates multiple events with spaces. Must be a valid event.

data Optional. Specifies additional data passed to the function.
function Required. Specifies the function to be executed when the event occurs.

Alternative Syntax

$(selector).bind({event:function, event:function, ...})

Try It Yourself

Parameter Description
{event:function, event:function, ...} Required. Specifies the event mapping, which includes one or more events added to an element and the function that runs when the event occurs.