jQuery bind()

The jQuery bind() event is used to attach one or more event handlers for selected elements from a set of elements. It specifies a function to run when the event occurs.

It is generally used together with other events of jQuery.

Syntax:

Parameters of jQuery bind() event

ParameterDescription
EventIt is a mandatory parameter. It specifies one or more events to attach to the elements. If you want to add multiple events they they must be separated by space.
DataIt is an optional parameter. It specifies additional data to pass along to the function.
FunctionIt is a mandatory parameter. It executes the function to run when the event occurs.
MapIt specifies an event map which contains one or more events or functions attached to the element.

Example of jQuery bind() event

Let's take an example to demonstrate jQuery bind() event.

Test it Now

Output:

Click on the statement.

Advantages of jQuery bind() event

  • It is compatible on various browsers.
  • It is quite easy and quick to bind event handlers.
  • It provides some shorthand and easy methods with click(), hover() etc. events for binding event handlers.

jQuery bind() example with mouseenter() and mouseleave() events

Let's take an example of jQuery bind() with mouseenter() and mouseleave() events.

Test it Now




Latest Courses