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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T10:51:57+00:00 2026-05-29T10:51:57+00:00

I ran into an interesting problem. On my site, i swap out content dynamically

  • 0

I ran into an interesting problem. On my site, i swap out content dynamically when hovering over a certain link. This is accomplished by something similar to:

$('#box').html($('#newcontent').html());

Now inside this #newcontent part, there is a <button>-Element to which I assigned a click event like this: (inside the $(document).ready()-function)

$("button#buttonName").click(function(){
  $("div#containerName").toggleClass("hidden");
  }

hidden is a css-Class doing the display:none magic. The container #containerName is outside both the element containing the button and the element containing the structure that is being changed with html().

Mockup of the structure at this point

<div id="somethingthatwhenhoveredoverwillswapthecontent">Hover over me!</div>

<div id="box">Change me!</div>

<div id="newcontent" class="hidden">I am renewed!
  <button id="buttonName">Show the weird box at the bottom</button>
</div>

<div id="containerName" class="hidden">
  I am content that is only shown when the button is clicked
</div>

So what happens is this: the page is loaded, the content swapping script works fine, but the button will not fire it’s click event, which for testing reasons didn’t even give an alert('whatever');. It looks like once the html() swaps the content from the <div id="newcontent"> to the <div id="box">, the event gets unbound (I suspect).

Is this just me not grasping a concept or is the whole approach done wrong?

  • 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-29T10:51:58+00:00Added an answer on May 29, 2026 at 10:51 am

    Behind the scenes jQuery is creating a new DOM element, rather than making a ‘copy’ of the original. Because of this it doesn’t have the event handler of the original. You can either manually re-assign the handlers along with your html() call, or you can use delegate() to add the event, like this:

    $("#box").delegate("#buttonName", 'click', function(){
        $("#containerName").toggleClass("hidden");
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I ran into a interesting issue today. Check out this pseudo-code: void Loop() {
I ran into an interesting iOS problem today involving a CATiledLayer. This only happend
I ran into an interesting problem at work today. I got a request to
I ran into an interesting problem. I have a MySQL database that contains some
I ran into an interesting (?) problem in the YUI rich edit demo on
An interesting problem I ran into today: what is the fastest way to count
While writing the touchesBegan handler for my view I ran into this interesting error.
Ran into this problem today, posting in case someone else has the same issue.
Ran into an interesting problem with a MySQL table I was building as a
This originally was a problem I ran into at work, but is now something

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.