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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T10:33:22+00:00 2026-06-17T10:33:22+00:00

File contents are given below. I have a button, load_button, whose click event triggers

  • 0

File contents are given below. I have a button, “load_button”, whose click event triggers a load() function. The html file loaded with the function contains another button, “my_button”. The callback of the load() function adds a handler for the click event of “my_button”. The problem is, every time I press “load_button”, a new click event handler is added, and the alert in the event handler pops up multiple times. I want to delete previously created “my_button” with its event handler, before creating the new one. What I tried is adding the following command, where its commented out in the file descriptions below.

$('#page').empty(); 

No luck. I wanted a general solution, since I’ll have other DOM objects to be removed. How can I remove them?

Also, it does not work when I replace

$('#page').on('click', '#my_button', function () {

with

$("#my_button").click(function()    {

Why isn’t it working? Isn’t the callback function of load() supposed to be run after the loading is done, and DOM objects are available?

main.html

<html>
    <head>
        ...
        <script src="main.js"></script>
    </head>
    <body>
        ...
        <a id="load_button">Load!</a>
        <div id="page">
        </div>
    </body>
</html>

1.html

<div>
    <a id="my_button">Go!</a>
</div>

main.js

$(document).ready(function(){

    $('#load_button').click(function()    {
//      $('#page').empty();
        $("#page").load('1.html', load_scripts());

    });
});

function load_scripts() {
    $.getScript('script.js');
}

script.js

$(document).ready(function(){

     $('#page').on('click', '#my_button', function () {
//   $("#my_button").click(function()    {
        alert('COWABUNGA!');
    });

});
  • 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-17T10:33:24+00:00Added an answer on June 17, 2026 at 10:33 am

    It looks like you don’t need to load scripts dynamically at all. Try a main.js that looks like this:

    $(document).ready(function(){
    
        $('#load_button').click(function()    {
            $("#page").load('1.html');
        });
    
        $('#page').on('click', '#my_button', function () {
            alert('COWABUNGA!');
        });
    
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a php file as given below. The page generates html content which
everyone, I have a big file in the format given below. The data is
I have this file: app/views/listings/list.html.erb in my rails project. Here are the contents of
I have a file whose contents are like this : control_data { some data
Given the following: >>> from lxml import etree >>> contents=open('file.xml').read() >>> node=etree.fromstring(contents) How would
So I have the following .htaccess file contents from my other project which is
I have AJAX call to one XML file and the source code is given
I am trying to read a CSV file and have it display the contents
I have a txt file which has data in the below format: int string
I have a guestbook.htm file in the directory named as Chrome (/home/chankey/Desktop/Chrome/guestbook.htm) whose content

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.