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.

0

1 Answer 1

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.

4
  • 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
    Commented Dec 22, 2011 at 9: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. Commented Dec 22, 2011 at 9: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
    Commented Aug 24, 2012 at 22:06
  • 2
    Forget it, it will be bind to the element itself in the DOM. Brain fart!! :(
    – Samuel
    Commented Aug 24, 2012 at 22:26

Not the answer you're looking for? Browse other questions tagged or ask your own question.