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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T11:50:19+00:00 2026-06-11T11:50:19+00:00

I am upgrading a web project containing 2 views with plenty of elements. At

  • 0

I am upgrading a web project containing 2 views with plenty of elements.

At this time, all elements have several events like mouseenter, mouseleave, click, … which are defined one by one during the web page rendering.

My question is : is it more efficient to use the last jQuery method .on() using an events map and a dynamic selector like this :

$("#main-container").on({
    mouseenter: function (event) {    
       //Do stuff
    },            
    mouseleave: function (event) {
       //Do stuff     
    },
    mousedown: function (event) {
       //Do stuff
    }
    },
    ".cartridge"
);

than the current events declarations:

$('[id^="cartridge"]').each(function(index) {       
    $(this).click(function(){
        //Do stuff
    }); 
    $(this).mouseenter(function(){
        //Do stuff
    }); 
    $(this).mouseleave(function(){
        //Do stuff
    }); 
});
  • 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-11T11:50:20+00:00Added an answer on June 11, 2026 at 11:50 am

    According to the jquery API of .on() it is more efficient cause there’s only one event attached to your #main-container and the events coming from the different .cartridge just need to “bubble up” to this container.

    From jquery API :

    In addition to their ability to handle events on descendant elements
    not yet created, another advantage of delegated events is their
    potential for much lower overhead when many elements must be
    monitored. On a data table with 1,000 rows in its tbody, this example
    attaches a handler to 1,000 elements:

    $("#dataTable tbody tr").on("click", function(event){
      alert($(this).text());
    });
    

    A delegated-events approach attaches an event handler to only one
    element, the tbody, and the event only needs to bubble up one level
    (from the clicked tr to tbody):

    $("#dataTable tbody").on("click", "tr", function(event){
      alert($(this).text());
    });
    

    http://api.jquery.com/on/ see “Direct and delegated events”

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

Sidebar

Related Questions

I have been trying to figure out the logic of upgrading web applications. Like
I have started upgrading one of our internal software applications, written in ASP.NET Web
I have a legacy web app running in Tomcat 5.0. This web app has
Hi I have a MVC 3 web project which has been deployed to Azure
Upgrading an rc to rtm web api project Default parameter binding for simple type
We've recently upgraded from VS2008 -> VS2010 (and hence upgrading from Web Deployment Project
I've just been upgrading an Azure project to Visual Studio 2010 and have been
MVC 4 Beta project fails to compile after upgrading to .Net 4.5. This happens
Is there a preferred method of gracefully upgrading a web site? I have a
I have a web project that I developed where one of the main functions

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.