Difference between .on('click') vs .click()

后端 未结 12 2473
礼貌的吻别
礼貌的吻别 2020-11-21 05:22

Is there any difference between the following code?

$(\'#whatever\').on(\'click\', function() {
     /* your code here */
});

and

12条回答
  •  悲&欢浪女
    2020-11-21 05:49

    They appear to be the same... Documentation from the click() function:

    This method is a shortcut for .bind('click', handler)

    Documentation from the on() function:

    As of jQuery 1.7, the .on() method provides all functionality required for attaching event handlers. For help in converting from older jQuery event methods, see .bind(), .delegate(), and .live(). To remove events bound with .on(), see .off().

提交回复
热议问题