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 customjQuery.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.