1

Possible Duplicate:
What's the difference between on and live or bind?

I've been noticing people referring to jQuery's .on() method to bind events. I looked up the documentation and it seems like it is new as of version 1.7. I was looking around and I was unable to find why I should use it and how it's different from just .bind(). Can I use .on() all the time now or is it for specific cases?

If anyone has any input or links explaining the difference, I would appreciate it.

Community
  • 1
  • 1
arb
  • 7,753
  • 7
  • 31
  • 66

2 Answers2

2

You can use on for all event bindings now. As the documentation states:

As of jQuery 1.7, the .on() method provides all functionality required for attaching event handlers.

You can use it as you would have used bind:

$(elem).on("click", function() {
    //Do stuff
});

You can also use it as you would have used delegate:

$(elem).on("click", "selector", function() {
    //Do stuff
});
James Allardice
  • 164,175
  • 21
  • 332
  • 312
1

This blogpost discusses it to some extent: http://blog.jquery.com/2011/09/28/jquery-1-7-beta-1-released/

nillls
  • 625
  • 4
  • 11