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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T18:15:59+00:00 2026-06-08T18:15:59+00:00

In the application that I’m currently creating, I am doing several AJAX calls to

  • 0

In the application that I’m currently creating, I am doing several AJAX calls to the server and replacing parts of my page with partial views. Everything seems to be working right except for my buttons which are “replaced” using the jQuery replaceWith() function.

In my actual code, I’m replacing a whole <div> not just a button, but the code found here will help illustrated my issue.

When the button is clicked, the JavaScript is called and thusly, that button is then updated. However, try to click on that button again, the same JavaScript will NOT be called or executed. There is some disconnect here that I’m missing. (In my mind, every time that the button with a class of “updateButton” is clicked, the javascript should be executed.) Please help me out.

Thanks

  • 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-08T18:16:00+00:00Added an answer on June 8, 2026 at 6:16 pm

    Event delegation.

    $(document).on('click','.updateButton',function (e) {
                e.preventDefault();
        var now = new Date().getTime();
    
       var newButton = "<span class='btn btn-info updateButton'>Update Button " + now + "</span>"
    
        $(this).replaceWith(newButton);
    });
    

    Demo: http://jsfiddle.net/D2RLR/896/

    Instead of binding the event to the button which will be removed (thus losing the event binding), bind it to an element that doesn’t get removed but is an ancestor of that button.

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

Sidebar

Related Questions

i am creating an application that pulls bookings from my local server in JSON
I am doing a application that deals with where Users can login and see
The application that I'm currently working on has a funky set up for the
Suppose that i have an application that connects to a sql server, and this
An application that uses Flask framework, can start the built-in werkzeug development server simply
I'm developing an application that uses Qt 4.7 with the goal of creating a
In an application that I am currently working on, a requirement is to bring
I'm creating an application that will store a hierarchical collection of items in an
I have a ColdFusion application that's behind an ISA Server. Part of the application
An application that I support has recently begun experiencing extended periods of time required

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.