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

  • SEARCH
  • Home
  • 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 7642827
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T09:17:20+00:00 2026-05-31T09:17:20+00:00

var $obj1 = $(‘a#one’); var $obj2 = $(‘a#two’); var $obj3 = $(‘a#three’); // Assume

  • 0
var $obj1 = $('a#one');
var $obj2 = $('a#two');
var $obj3 = $('a#three');

// Assume $('a#one, a#two, a#three') wasn't an option.

How do I assign one (same) event handler e.g. click() to those three jQuery objects? Essentially, I am looking for a more efficient way of doing:

$obj1.click(function() { /* Code A */ });
$obj2.click(function() { /* Code A */ });
$obj3.click(function() { /* Code A */ });
  • 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-05-31T09:17:22+00:00Added an answer on May 31, 2026 at 9:17 am

    Only (very) marginally shorter, but:

    $([$obj1, $obj2, $obj3]).click(function() { });
    

    You would want to define your handler outside of the first anonymous function though, so you’d really probably be better off with Jonas H’s method. Just throwing another suggestion out there.

    Note: you could technically do a hybrid, but it’s quite lengthy:

    var f = function() { };
    $([$obj1, $obj2, $obj3]).click(f);
    

    Really this question is only useful if you want to avoid the $a.click(f) over and over again, which is truly a better option than this jQuery abuse. 🙂

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

Sidebar

Related Questions

Can anybody tell me, if I call ex. var obj1 = $('#element_id') var obj2
I have two objects: object1={ type: 'obj1', nName: 'nName' } object2={ type: 'obj2', pName:
The object var obj = { uniquestring1: { obj1: 'content', obj2: 'content' }, uniquestring2:
var array1:Array = new Array(); var array2:Array = new Array(); var obj1:Object = new
var array1:Array = new Array(); var array2:Array = new Array(); var obj1:Object = new
Im trying to call functions with same signature. Example: There are two functions with
I have a complex LINQ query like var results = from obj1 in context.ProcessBases
Assume I have an empty object like so: var object = {}; How can
I have the following LINQ query: var query = (from p in obj1 group
I've: function Obj1(param) { this.test1 = param || 1; } function Obj2(param, par) {

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.