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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T09:14:42+00:00 2026-05-29T09:14:42+00:00

I update a container with AJAX. Which one is better in terms of performance?

  • 0

I update a container with AJAX. Which one is better in terms of performance? Pseudo-code:

$.post('get_something.php',function(data){
    $('#container').html(data).find('a').bind('click',function(){
        console.log('Doh!');
    });
});

Or this?

$('#container a').live('click',function(){
    console.log('Doh!');
});

$.post('get_something.php',function(data){
    $('#container').html(data);
});
  • 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-29T09:14:43+00:00Added an answer on May 29, 2026 at 9:14 am

    Firstly, I wouldn’t recommend using live at all (and the jQuery team have deprecated it). I’d use delegate (or the new version of on) with a more targeted container (in your case, #container) than the document as a whole.

    If you do that, performance at click-time will be so close to the same as to make no difference (we’re dealing with a user-generated event here, the odd extra couple of milliseconds makes no never mind).

    There are other considerations to (um) consider, though. Suppose we have this markup:

    <div id="container">
        <div id="wrapper">
            <a>A link</a>
        </div>
    </div>
    

    …and this code:

    $("#container").delegate('a', 'click', function() {
        // Do something with the click
        console.log("Link was clicked");
    });
    $("#wrapper").click(function() {
        return false;
    });
    

    Since the a is the deepest element, you’d expect a click on the a to be handled by the first handler and to see the console.log entry. But you won’t, because the click isn’t actually handled until it reaches the container — and in this case, it won’t reach the container because the wrapper element in-between them stops the event.

    It’s not a negative (I find delegate hugely useful and use it all the time), it’s just something to consider when you’re designing how you handle things.

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

Sidebar

Related Questions

I'm attempting to send a piece of data through jQuery .ajax() to a PHP
I have to work through some code and found the following function, which I
My ascx control inside a container update panel does a full page refresh when
UPDATE!!! Suggested answer is NOT correct, my mistake. The #container DIV should've had float:left;.
I have a MDI container form, and some child forms that update their title
I have a tab container with 5 tabs, each tab contains an update panel.
How to update ms access table which contains single column with multiple rows. the
i have a file which contains a lot of update query and some other
I am trying to UPDATE a mysql TEXT data-type column with a string contains
I am trying to create a Ajax Toolkit TabContainer which has Previous and Next

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.