Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

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.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8506227
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T02:32:10+00:00 2026-06-11T02:32:10+00:00

Say I have two click handlers which perform the same functionality : $(‘#div1’).click(function(event) {

  • 0

Say I have two click handlers which perform the same functionality :

$('#div1').click(function(event) {  
alert('here');                              
});

$('#div2').click(function(event) {  
alert('here');                              
});

How can I combine these two handlers into one instead of repeating the call to alert ?

Something like :

$('#div1').click.('#div2').click(function(event) {  
alert('here');                              
});
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T02:32:12+00:00Added an answer on June 11, 2026 at 2:32 am

    Try this:

    $('#div1, #div2').click(function(event) {  
       alert('here');                              
    });
    

    Furthermore, if you have a lot of div elements, contained in a common parent, you may take benefit of event delegation and attach a single handler to the parent itself, like so:

    $('.common-parent').on('click', 'div', function(event) {  
       ...                          
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say I have labels and I attach two click events to it: $('#l1').bind('click',function(){
Let's say you have two selectors like this: $(.class1, .class2).click(function() { $(this).hide(); }); It
Say I have two classes which extend Event : public class CustomEventOne extends Event
Let's say I have these two functions: function z(a,b,c){ $(#d).click(function(){ var sum = a+b+c;
Say I have two functions that expect ...rest parameters private function a(...myParams):void { trace(myParams.length);
I have two functions here say animation1 and load1 they work like that: function
Let's say I have two div , #move and #object respectively, and a function
I have two activities, say LoginActivity which contains a login UI and HomeActivity .
Say we have two activities, Activity1 and Activity2. In Activity1's onClick() method, we have
Say I have two Java apps that I wrote: Ping.jar and Pong.jar and they

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.