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 7914835
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T14:15:06+00:00 2026-06-03T14:15:06+00:00

I wanted something similar to $(‘#el1’).bind({ click,function(e){ alert(‘clicked on el1’); }, }) $(‘#el2’).bind({ click,function(e){

  • 0

I wanted something similar to

$('#el1').bind({
    click,function(e){
        alert('clicked on el1');
    },
})
$('#el2').bind({
    click,function(e){
        alert('clicked on el2');
    },
})

when using ‘on’ .
I was looking for something like :

$(document).on({
    click:'el1',function(e){
        alert('clicked on el1');
    },
    click:'el2',function(e){
        alert('clicked on el2');
    }
})

This does not work.

[edited]
I guess I need to be more clear. The different functions have nothing in common. Probably something like this would do :

$(document).on({
    click:'el1',function(e){
        alert('clicked on el1');
    },
    click:'el2',function(e){
        $('body').css('background-color','green');
    }
})

I currently see using switch case solution to be the closest to the one I was looking for.

  • 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-03T14:15:08+00:00Added an answer on June 3, 2026 at 2:15 pm

    If your handler functions are unrelated, don’t try to smash them into one. Readability will suffer.

    Instead, be clear and attach your handlers separately.

    $('#el1').click(function() { ... });
    $('#el2').click(function() { ... });
    

    That is instantly recognizable as being two separate, unrelated functions. In the future, it will be easier to maintain and modify this code. Someone new to your code doesn’t have to learn wacky conventions; this is how jQuery is supposed to work.

    $('#el1,#el2').click(function() {
        switch (this.id) {
            case 'el1': ... break;
            case 'el2': ... break;
        }
    });
    

    Ew.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

If I wanted to represent states or options or something similar using binary flags
I wanted to write something basic in assembly under Windows. I'm using NASM, but
If I wanted to do something like this: collection.each do |i| return nil if
does PHP support something like ampersand in bash (forking)? Let's say I wanted to
I wanted to do something very similar to a question that has already been
Just out of curiosity i wanted to make something similar to what pretty much
We are planning to develop something similar to LinkedIn using Python and Django. As
after reading jquery xml select I wanted to do something similar with this rdf/xml:
Is there in PHP something similar to JavaScript's: alert(test || 'Hello'); So, when test
I am trying to create something like this: This example creates view using a

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.