36

I know that the on method, is supposed to replace live, delegate etc. But is there any point in using it on places where you're currently using the click event? For example on elements that are not dynamically generated.

Xyz
  • 5,955
  • 5
  • 40
  • 58
Johan
  • 35,120
  • 54
  • 178
  • 293

1 Answers1

28

It's not specifically worth replacing click(), as in the jQuery source it converts all the 'shortcut' event handlers (like click(), keyup() etc.) to on("event", fn) anyway.

Rory McCrossan
  • 331,213
  • 40
  • 305
  • 339
  • 2
    From the docs: `There are shorthand methods for some events such as .click() that can be used to attach or trigger event handlers. For a complete list of shorthand methods, see the events category`. So the answer would be no, just as @Rory is saying I think. – Derk Arts Dec 22 '11 at 09:04
  • 9
    Just as you didn't use `.bind("click")` instead of `.click()` before, you don't need to use `.on("click")` instead of `.click()` now. – Andreas Eriksson Dec 22 '11 at 09:05
  • 1
    But the shorthand method .click() will call .on() and then will attach the event handler at the root level and the bubbling phase will traverse all the structure from the element to the root. With .on() directly, you can attach the click event listener to the immediate parent node and this will reduce the bubbling phase but in case of click event, I think it will be a very very small improvment. – Samuel Aug 24 '12 at 22:06
  • 2
    Forget it, it will be bind to the element itself in the DOM. Brain fart!! :( – Samuel Aug 24 '12 at 22:26