I understand the difference between Live and Bind but when should I use use .bind()
over a 'standard' event method as shown below.
Are there any key differences in the way these two calls work?
$('.clickme').bind('click', function() {
// Handler called.
});
$('.clickme').click(function() {
// Handler called.
});
The bind() is an inbuilt method in jQuery which is used to attach one or more event handlers for selected element and this method specifies a function to run when event occurs. event: This is an event type which is passed to the selected elements.
jQuery bind() Method The bind() method attaches one or more event handlers for selected elements, and specifies a function to run when the event occurs.
jQuery | error() Method The error() method in jQuery is used when an element encounters an error that is the element is not loaded correctly. The error() method attaches a function to run when an error event occurs or it triggers the error event.
They're effectively the same. However, using bind()
allows you to make use of namespaced events. This is especially useful when writing plugins.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With