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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T18:40:54+00:00 2026-05-14T18:40:54+00:00

I have two divs for different sections of my webpage, a working and a

  • 0

I have two divs for different sections of my webpage, a working and a reference section. One is fixed size, the other is variable sized and they are vertically stacked. I am trying to design it so that if you want to work on something in the reference pane, you click a link and it swaps all the data between the two panes. My idea was to do the following:

var working = $("#working_pane").html();
var ref = $("#reference_pane").html();

$("#working_pane").html(ref);
$("#reference_pane").html(working);

The problem with this, is it seems that any javascript referenced inside of these panes (for example, in place editors) get broken upon switching. No javascript errors occur, it’s just that nothing happens, like the javascript ties are broken.

Is there any to move the html without breaking the javascript contained?

  • 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-14T18:40:55+00:00Added an answer on May 14, 2026 at 6:40 pm

    When you are working with bits of an HTML document, you should aim to work with the Node objects that are the content as the browser sees it, not HTML strings.

    To get HTML the browser has to look at the Nodes and serialise them to a string. Then when you assign that HTML to another part of the document (with innerHTML or jQuery html(...)), you are telling the browser to destroy all the content that was previously in the element, laboriously parse the HTML string back into a new set of Node objects, and insert these new Nodes into the element.

    This is slow, wasteful, and loses any aspect of the original Node objects that can’t be expressed in serialised HTML, such as:

    • event handler functions/listeners (which is why your editors are breaking)
    • variable references other JavaScript code has to the Nodes (also breaks scripts)
    • form field values (except, partially, in IE due to a bug)
    • custom properties

    So — and this applies whether you’re using jQuery or the plain DOM — don’t throw HTML around! Take the original node objects and insert them into the place you want them (they’ll leave the place they originally were automatically). The references stay intact so scripts will keep working.

    // contents() gives you a list of element and text node children
    var working = $("#working_pane").contents();
    var ref = $("#reference_pane").contents();
    
    // append can be given a list of nodes to append instead of HTML text
    $("#working_pane").append(ref);
    $("#reference_pane").append(working);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have two divs one floated to the left and the other to the
I have two divs inside a container div. One need to float left the
I have two divs: -A header bar, which is fixed while scrolling, and stuck
I have two divs next to the each other which background color is white.
I have two divs. One has an id that is a string representation of
Okay I have two classes for two links and two divs with different information.
I have two sibling divs sitting below each other, both contained in the same
I have two divs inside of a container. One on the left, one on
As the title explains, I have one container div, containing two floating divs of
I have a page which has DIVs which contain short phrases (one-two words) of

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.