Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In JQuery when should you use .bind() over .click() - or any other given event?

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.
});
like image 529
Andrew Avatar asked Feb 01 '11 17:02

Andrew


People also ask

What is the purpose of using bind () method in jQuery?

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.

Which of the following is used to bind a handler to one or more events for an element?

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.

Which jQuery method triggers or binds a function to the error event of selected elements?

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.


1 Answers

They're effectively the same. However, using bind() allows you to make use of namespaced events. This is especially useful when writing plugins.

like image 190
Shawn Chin Avatar answered Sep 21 '22 21:09

Shawn Chin