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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T16:30:07+00:00 2026-06-15T16:30:07+00:00

This is a rather strange issue with jquery. I am loading a div <div

  • 0

This is a rather strange issue with jquery. I am loading a div

<div id="container">

on page load. Each record is tabular data with a ‘delete’ ajax function associated with it. When the page loads and clicking the ‘delete’ link, the ajax call fires off just fine.
However, once the event is fired, the data is returned from the ajax call, and the div is populated with data (but the page does not refresh or reload)
When I click the link again, the ajax script will not fire.
Here is my code:

$(document).ready(function() {
    $("button.done").button({
    }).click(function() {
        var BatchID = $("input#BatchID").val();
        var Amount = $("input#Amount").val();
        var Name = $("input#CheckName").val();
        var Check_Number = $("input#Check_Number").val();
        var Company = $("select#Company").val();
        var Department = $("select#Department").val();
        $.ajax({
            type: 'GET',
            url: '/app/usagCheckEntryWS.html',
            data: {
                "BatchID" : BatchID,
                "Amount" : Amount,
                "Name" : Name,
                "Check_Number" : Check_Number,
                "Company" : Company,
                "Department" : Department
            },
            success: function (data) {
                    var ang = '';
                    var obj = $.parseJSON(data);
                    $.each(obj, function() {
                       ang += '<table><tr><td width="45">' + this["RefID"] + '</td><td width="140">' + this["Name"] + '</td><td width="95">' + this["CheckNumber"] + '</td><td align="right" width="70">$' + this["Amount"] + '</td><td width="220" style="padding-left: 15px;">' + this["Description"] + '</td><td><div class="delete" rel="' + this["RefID"] + '"><span>Delete</span></div></td></tr></table>';
                    });
                    $('#container').html(ang);
                    $("input#Amount").val('');
                    $("input#CheckName").val('');
                    $("input#Check_Number").val('');
                    $("select#Company").val('MMS');
                    $("th#dept").hide();
                    $('input#CheckName').focus();
            }
        });
    });
});

  • 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-15T16:30:09+00:00Added an answer on June 15, 2026 at 4:30 pm

    When you remove an element and then replace it (via javascript), it loses any event bindings that were added to it on page load.

    (This also applies to content added to the page after page load – i.e. ajax loaded content)

    There are several possible solutions for this.

    1) Encapsulate your “binding” code and call it both on page load and immediately after the element in question gets added back to the page. For example:

    $(document).ready(function(){
        // bind event handlers when the page loads.
        bindButtonClick();
    });
    
    function bindButtonClick(){
        $('.myClickableElement').click(function(){
            ... event handler code ...
        });
    }
    
    function updateContent(){
        $.ajax({
            url : '/ajax-endpoint.php',
            data : {'onMyWay' : 'toServer'},
            dataType : 'html',
            type : 'post',
            success : function(responseHtml){
                // .myClickableElement is replaced with new (unbound) html element(s)
                $('#container').html(responseHtml);
    
                // re-bind event handlers to '.myClickableElement'
                bindButtonClick();  
            }
        });
    }
    

    2) The more elegant way to handle this: use jQuery’s .on() method. With it, you are able to bind event handlers to elements other than the event target – i.e. an element that never gets removed from the page.

    $(document).ready(function(){
        $('body').on('click','.myClickableElement',function(){
            ... event handler code ....
        });
    });
    

    Some further explanation:

    The .on() method uses event delegation to tell a parent element to retain your event handler code (3rd argument), and fire it when the event target (2nd argument) has a certain type of event (1st argument) performed on it.

    If you are using a version of jQuery prior to 1.7 use the now deprecated delegate method which essentially does the same thing.

    Also, it is worth noting that because of the way events “bubble up” through the dom tree, the event target (2nd argument of .on() method) must be a descendant of the delegating element (jQuery object’s selector). For example, the following would NOT work

    <div id="container-1">
        <div>
            <div id="another-div">
                Some Stuff
            </div>
        </div>
    </div>
    
    <div id="container-2">
        <a id="click-me">Event Target!!!</a>
    </div>
    
    <script type="text/javascript">
        $('#container-1').on('click','#click-me',function(){
            ... event handler code ....
            // This will never execute, should've used '#container-2', or 'body', or 'document' instead of '#container-1'
        });
    </script>
    

    The body or document elements are usually safe choices since typically every element on the page is a descendant.

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

Sidebar

Related Questions

So i have this rather strange issue, i am trying to line up some
This is a rather strange issue.. I am not able to publish a facebook
I'm having this rather strange issue - upon a button click, the program initializes
Found this rather strange bug in IE8; element.style.top is limited to 1342177 pixels. Even
I'm having a rather strange issue with Entity Framework 4.3 in my MVC application.
I'm having a rather strange issue with the Google Maps javascript API and HTML5
I have a rather strange issue, I'm using Audio Units from CoreAudio to playback
I've run into a rather strange problem. I have a div that is rotatable
This is a really strange issue. I have developed a small MVC application and
I am facing a strange problem. My PHP page has following code. echo <div

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.