jQuery bind()
The bind()
method in jQuery is used to attach one or more event handlers to a selected element. This method can be used to bind custom events as well, in addition to the standard DOM events.
Syntax
The bind()
method has the following syntax:
$(selector).bind(event[, data], handler)
- The
event
parameter specifies the event type to bind to. - The optional
data
parameter specifies additional data to pass to the event handler. - The
handler
parameter specifies the function to run when the event is triggered.
Use
The bind()
method is useful for attaching event handlers to elements dynamically after the page has loaded. It is also useful for binding multiple events to the same element, as well as binding custom events.
Example
Here is an example of using the bind()
method to attach a click event handler to a button: