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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T12:15:29+00:00 2026-05-25T12:15:29+00:00

I am a bit confused about how differently the jQuery append() and the Javascript

  • 0

I am a bit confused about how differently the jQuery append() and the Javascript appendChild() functions handle an Element that calls the document.write() function within.

Here’s my HTML Code:

<div id="main-area">
</div>

<div id="temp-area">
    <div id="content">
        <script>
            document.write('Lorem Ipsum Dolor...');
        </script>
    </div>
</div>

I basically want to put the whole Element ‘#content’ and all its Contents, including the ‘Lorem Ipsum’ Javascript Bit from ‘#temp-area’ to ‘#main-area’. My first approach was simple jQuery:

target = jQuery('#main-area');
content = jQuery('#content');
target.append(content);

This works, but with one exception: the ‘Lorem Ipsum Dolor’ text is written once in the ‘#content’ Element where it belongs, now within the ‘#main-area’ div, AND once beneath both divs at the bottom of the page (without the ‘#content’ div wrapping the text). Of course, I want the text to be shown only once, within the ‘#content’ div. If I write the Lorem Ipsum text as static HTML, the whole thing works just fine, so it’s got to have something to do with the document.write function and how this affects the DOM Tree, right? So i experimented a little more and came to this solution:

target = jQuery('#main-area').get(0);
content = jQuery('#content').get(0);
target.appendChild(content);

With this Code, the Lorem Ipsum Text is only written once in the HTML Document, and exactly where i want it to be. Problem solved.

But i don’t get how and why this approach works and the other one doesn’t. So I’m not asking for a solution to my problem, but for an explanation as to why both approaches handle things so differently to understand whats going on here. Is there perhaps a wholly different solution to the scenario that I’m missing and that’s easier to understand?

(i tested in firefox and opera)

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-05-25T12:15:29+00:00Added an answer on May 25, 2026 at 12:15 pm

    Please read this question and answer.

    Basically, the <script> needs to be added to the DOM directly to be executed via appendChild. So I guess as a child of another element this won’t work. But if added through jQuery, then jQuery will manage any script content itself and make sure it gets executed. See jQuery source and search for

    clean: function( elems, context, fragment, scripts ) {

    This is a function that strips <script> tags out, and they ultimately will be executed by jQuery.

    Here’s a small jsfiddle demo of options.

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

Sidebar

Related Questions

I'm a bit confused about the memory leaks in PHP. I've read that PHP
I am a bit confused about socket programming in C. You create a socket,
I am bit confused about ADO.Net Data Services. Is it just meant for creating
I'm a bit confused about how many controllers I need, and when I can
I'm a bit confused about inheritance under sqlalchemy, to the point where I'm not
I'm a bit confused about the use of all the IEnumerable<T> extension methods, intellisense
I am a little bit confused about 2 things. Firstly when I create an
I'm a bit confused about how to overload the stream operators for my class
I am a bit confused about this. If you're building a distributed application, which
I'm a bit confused about handling an array of objects in C++, as I

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.