Click here to Skip to main content
12,952,792 members (35,969 online)
Click here to Skip to main content
Add your own
alternative version


7 bookmarked
Posted 11 Sep 2012

Binding Multiple Events in jQuery

, 11 Sep 2012 CPOL
Rate this:
Please Sign up or sign in to vote.
Bind a JavaScript function to multiple events using jQuery


Sometimes, we would like to use the same function for more than one event of an element. Normally, we create a function and call on different events. But sometimes we find, it is a duplication of calling function. I did some Googling and found a solution to use jQuery function.

A piece of code where I needed to call function twice:

function () {
    $(this).next().css("display", "none");
}).focus(function () {
    $(this).next().css("display", "none");

To avoid duplication, we will create a function and call from both the events. But still a function name will be duplicated there.

Now using jQuery, we can bind multiple events on single function. See here how we can make that simpler.

$("#textbox").bind("click focus",
   function () {
       $(this).next().css("display", "none");


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Mehul M Thakkar
Technical Lead
India India
Mehul Thakkar is having 8 yrs of experience in IT industry. He is having good command over Ms .Net and Ms Sql Server

You may also be interested in...

Comments and Discussions

Question"on" method Pin
ColinBashBash9-Oct-12 8:22
memberColinBashBash9-Oct-12 8:22 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170525.1 | Last Updated 12 Sep 2012
Article Copyright 2012 by Mehul M Thakkar
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid