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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T19:34:06+00:00 2026-06-17T19:34:06+00:00

I have a site full of AJAX so I need to delegate methods to

  • 0

I have a site full of AJAX so I need to delegate methods to document clicks, assuming I have jQuery library too.
I just want to know what’s more efficient between these two codes:

$(document).on('click', '.delegate1', function(){
    doSomethingForDelegate1();
}).on('click', '.delegate2', function(){
    doSomethingForDelegate2();
});  

Or:

$(document).on('click', function(event){
    var element = $(event.target);
    if(element.hasClass('delegate1')){
        doSomethingForDelegate1();
    } else if(element.hasClass('delegate2')){
        doSomethingForDelegate2();
    }
})  

I want to implement the code that will have less impact on client’s execution time and therefore have a faster site. I know that maybe the difference won’t be much but it’s always better to work faster 😉

If there’s a method that’s faster than these 2 methods it’s welcome too. Thanks.

If the difference isn’t noticeable enough then I want to know what algorythm is cleaner, binding an event for each delegate or bind a single event and compare classes.

  • 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-17T19:34:08+00:00Added an answer on June 17, 2026 at 7:34 pm

    The 2nd method can be efficient when there are many elements that are being added to the DOM at a later time. SO attaching a single event to the document and delegating can really speed up the application .

    But if the number of elements created and needed to be attached are not huge, both should perform at the same rate..

    I would go with the 1st approach as it is lot more cleaner.

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

Sidebar

Related Questions

I want to have site wide default settings for all jQuery validation uses on
My site uses AJAX, and it seems like I have to include the full
I have noticed that sites like http://hypem.com which is a full ajax site have
I am working on an ASP.Net Full-Ajax site. Because all operations have doing by
I want to use just the slide transitions / AJAX navigation component of jQuery
In my live site I have php include() and require() that have full path
So I have site list on certain pages that basically just have links to
I have a site that i want to redirect all requests accept for 1
I have a site that collects URLs. A full HTTP URL is entered into
Currently I have a web site full of static pages. This minimizes web server

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.