Latest web development tutorials

jQuery bind () method

jQuery Event Methods jQuery Event Methods

Examples

Adding to the <p> element a click event:

$ ( "P"). Bind ( "click", function () {
alert ( "This paragraph is clicked.");
});

try it"

Definition and Usage

bind () method to add one or more event handlers, and function to run when the event occurs to the selected element.

JQuery from version 1.7 onwards, ON () method is the preferred method is to add the selected element event handlers.


grammar

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

参数 描述
event 必需。规定添加到元素的一个或多个事件。

由空格分隔多个事件值。必须是有效的事件。
data 可选。规定传递到函数的额外数据。
function 必需。规定当事件发生时运行的函数。
map 规定事件映射 ( {event:function, event:function, ...}) ,包含要添加到元素的一个或多个事件,以及当事件发生时运行的函数。


Examples

More examples

Add multiple events
How to add more events to the element.

Use event map
How to use the event map to add some events / functions to the selected element.

Data passed to the function
How to name a custom event handler pass data.


jQuery Event Methods jQuery Event Methods