11

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.
});
Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Andrew
  • 9,967
  • 10
  • 64
  • 103

5 Answers5

11

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

Shawn Chin
  • 84,080
  • 19
  • 162
  • 191
4

in "bind" you can use multiple events

$('#foo').bind('mouseenter mouseleave', function() {
  $(this).toggleClass('entered');
});
Ergec
  • 11,608
  • 7
  • 52
  • 62
2

They are the same. See here

Community
  • 1
  • 1
bpruitt-goddard
  • 3,174
  • 2
  • 28
  • 34
0

I use the explicit methods when available. I use the bind when a method isn't available like for window.onbeforeunload

The other time to use bind is if your are developing and switching between "live" and "bind".

cmar
  • 161
  • 2
  • 6
0

use .bind when you want to bind to "event.namespace"

Actaully almost always use .bind and almost always use namespaces.

Raynos
  • 166,823
  • 56
  • 351
  • 396