Is there any benefit to using .click() over .bind('click') or vice-versa besides the amount of typing you have to do?
Is there any benefit to using .click() over .bind(‘click’) or vice-versa besides the amount
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.
Based on some very unscientific and very quick tests using .bind vs .click represents a 15% (roughly) speed up, as tested over 50,000 iterations of each.
Its not huge, unless you’re binding massive numbers of events, but I’m always of the thought that making it faster when it takes no effort is something worth doing.
My quick & dirty test: http://jsbin.com/ixegu/edit
Other Benefits – Bind Multiple Events
Since you accepted this answer, I thought I’d add a bit more. You can also bind multiple events with .bind, for example:
There’s another syntax for binding multiple events via the bind() method. From the docs:
Pass extra data on event with bind()
Then there’s the ability to pass arbitrary data when you create the bind (only at the time you create the bind)
The above alerts “This is a happy link” when you click on happy, and “This is a sad link” when you click on sad. See http://jsbin.com/idare/edit for an example.
Read the docs
You can always find out more here.