🚨 Time is Running Out: Reserve Your Spot in the Lucky Draw & Claim Rewards! START NOW

Code has been added to clipboard!

Before on Method: Learn How jQuery .bind() Was Used

Reading time 1 min
Published Jan 11, 2018
Updated Sep 27, 2019

jQuery bind: Main Tips

  • The jQuery .bind() method has been deprecated since version 3.0 of jQuery. Use .on() method instead.
  • .bind() added event handlers to the selected elements.

How .bind() Worked

The jQuery .bind() method was used to attach event handlers to elements.

Example
$("span").bind("click", () => {
   $("span").text("Clicked!");
});

jQuery .bind() followed this syntax:

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

There were three parameters relevant to jQuery .bind():

  • event defined a standard JavaScript event or a custom jQuery.event object.
  • data represented the additional data to be passed to the handler function.
  • function specified the handler function to attach and run when the specified event was triggered.

Note: .bind() added handlers directly to selected elements. Therefore, the elements had to be present when the function occured. For more flexibility, .on() was used.