0

I have been searching around without finding an satisfying answer. What is the difference between the 2 following event-handlers.

$('#div').on('click', function(){
    //do something
});

and

$('#div').click(function(){
    //do something
});

I know that in the $('#div').on('click', function(), you can send in more div or class-selectors in addition to 'click', but is that it?

I'd love to hear what else separates them, and if there are times where one is better to use than the other.

Thanks

Nilzone-
  • 2,766
  • 6
  • 35
  • 71

1 Answers1

0

.on() can be used to bind event to elements that is not present at the page load, but may appear later. There are other benefits also.

mekwall
  • 28,614
  • 6
  • 75
  • 77
Devjit
  • 375
  • 1
  • 10