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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T12:30:21+00:00 2026-05-22T12:30:21+00:00

I append to div container some div’s : $.ajax( { type: GET, url: /LoadedData,

  • 0

I append to div container some div’s :

 $.ajax(
    {
        type: "GET",
        url: "/LoadedData",
        data: { "pageNumber": pageNumber },
        success: function (result) {
            $('.Container').append(result);
        }
    }

and when i try to click on new div i just can’t. I omit this by using

$('.Container').live('click', function () {

    });

but can You tell my why I can’t do this without using live() ?

  • 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-22T12:30:22+00:00Added an answer on May 22, 2026 at 12:30 pm

    You’re binding your event handlers to elements that exist when the page loads.

    Elements that are added later must be bound at that time.

    The alternative is to utilize event delegation. jQuery has 2 delegation methods, .live() and .delegate().

    What happens with those methods is that the handler is not bound to the elements in question, but rather bound to some container. When the click event bubbles up to the container, jQuery checks to see if the element clicked matches the selector you gave it, and if so, fires the handler.

    Visualize it like this:

    $('.item').click(function() { /* do something */ });
    

    Binds like this:

    <div class="Container">
        <div class="item">click me</div> <!-- handler is bound -->
        <div class="item">click me</div> <!-- handler is bound -->
        <div class="item">click me</div> <!-- handler is bound -->
    </div>
    

    But this:

    $('.Container').delegate('.item','click', function() { /* do something */ });
    

    Binds like this:

    <div class="Container">    <!-- handler is bound to container, and runs the
                                     ".item" selector when a click occurs inside -->
        <div class="item">click me</div> 
        <div class="item">click me</div>
        <div class="item">click me</div> 
    </div>
    

    So if you add additional .item elements to the .Container, they will just work, because the handler processes all clicks inside .Container.

    <div class="Container">    <!-- handler is bound to container, and runs the
                                     ".item" selector when a click occurs inside -->
        <div class="item">click me</div> 
        <div class="item">click me</div>
        <div class="item">click me</div> 
    
        <div class="item">click me</div>  <!-- new item -->
        <div class="item">click me</div>  <!-- new item --> 
    </div>
    

    So the click events on the new items bubble just like on the original ones.

    The .live() method works the same as the .delegate() method. It just uses the document as the default container, which means that it has to process all clicks on the page.

    Because of this, I prefer .delegate().

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

Sidebar

Related Questions

$.post('includes/script.php', $(this).serialize(), function(data) { $('body').append(data); }); alert ($('#new').length) php script is <php echo <div
Let's say I have a situation like so: $(window).load(function() { $(body).append(<div id='container'></div>); var i=1;
function moveAround(){ $('p').append($('#div')); } Above code will move div after p element as a
I've got an empty DIV element in which I append images by using function
I am retrieving some JSON data with the following function. It is called when
I have list of divs with some data in there: <div style=border: 1px solid
A button click fires my function that fetches image data via an AJAX-call: $(#toggle_album).click(function
I am trying to append some links with data and a click handler to
I have some html: <body> <h1 id=header></h1> <div id=container> <div id=left> </div> <div id=content>
Based on some data I'm cloning a div with a checkbox and check it

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.