What is different between two below statement in jQuery:
1) with .bind
$("#username").bind('click',function(){
//@todo
});
2) without .bind()
$("#username").click(function(){
//@todo
});
So, when I need to use one of them?
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. If you read the docs for
.clickyou will notice the following line:You can confirm this by taking a quick look at the jQuery source:
I tend to use
.clickover.bind, simply because it’s quicker to write. However,.bindcan be used to attach the same listener to multiple events so it’s useful in that case:To expand upon the comment by @Tomalak,
.bindis also useful when working with custom events. For pretty much any other event, there is a shortcut method just like.click. The jQuery source is as follows: