To add a click event handler to an element, is .bind('click') or .click better? What makes the difference? Any performance aspects?
To add a click event handler to an element, is .bind(‘click’) or .click better?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
There is no difference. Internally,
clickjust callson, andbindalso just callson. So for a very minor speed increase, just useon:Here’s the relevant part of the jQuery 1.7.2 source for the
.click()method:And the source of the
.bind()method:If you’re using jQuery below version 1.7…
Note that the
.on()method was introduced in jQuery 1.7. If you are using an older version,.click()will internally just call.bind()instead. Here’s the source of.click()from 1.6.2: