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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T20:05:45+00:00 2026-05-13T20:05:45+00:00

The question is, comparing concatination using innerHTML and appending a text node to an

  • 0

The question is, comparing concatination using innerHTML and appending a text node to an existing node. What is happening behind the scene?

My thoughts around this so far:

  • I’m guessing both are causing a
    ‘ReFlow’.
  • The latter (appending a text node), from what I know, also causes a complete rebuild of the DOM (correct? Are they both doing this?).
  • The former seems to have some other nasty side effects, like causing previously saved references to child nodes to the node I’m modifying innerHTML, to no longer point to ‘the current DOM’/’correct version of the child node’. In contrast, when appending children, references seem to stay intact. Why is this?

I’m hoping you people can clear this up for me, 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-13T20:05:45+00:00Added an answer on May 13, 2026 at 8:05 pm

    The latter (appendChild) does not cause a complete rebuild of the DOM or even all of the elements/nodes within the target.

    The former (setting innerHTML) does cause a complete rebuild of the content of the target element, which if you’re appending is unnecessary.

    Appending via innerHTML += content makes the browser run through all of the nodes in the element building an HTML string to give to the JavaScript layer. Your code then appends text to it and sets innerHTML, causing the browser to drop all of the old nodes in the target, re-parse all of that HTML, and build new nodes. So in that sense, it may not be efficient. (However, parsing HTML is what browsers do and they’re really, really fast at it.)

    Setting innerHTML does indeed invalidate any references to elements within the target element you may be holding — because those elements don’t exist anymore, you removed them and then put in new ones (that look very similar) when you set innerHTML.

    In short, if you’re appending, I’d use appendChild (or insertAdjacentHTML, see below). If you’re replacing, there are very valid situations where using innerHTML is a better option than creating the tree yourself via the DOM API (speed being chief amongst them).

    Finally, it’s worth mentioning a couple of other alternatives:

    • append is a relatively recent addition to the DOM (but has excellent support other than truly obsolete browsers). It appends one or more items to the element, where the items can be nodes, elements, or HTML strings defining nodes and elements. Unlike appendChild, it supports HTML strings as well as nodes, and alsos supports multiple arguments. For your use case, it’s less cumbersome than the next option in this list: parent.append(htmlString).
    • insertAdjacentHTML inserts nodes and elements you supply as an HTML string into or next to an element. You can append to an element with it: theElement.insertAdjacentHTML("beforeend", "the HTML goes here"); The first argument is where to put the HTML; your choices are:
      • "beforebegin" (outside the element, just in front of it)
      • "afterbegin" (inside the element, at the beginning)
      • "beforeend" (inside the element, at the end)
      • "afterend" (outside the element, just in after it)
        Note that "afterbegin" and "beforeend" insert into the element itself, whereas "beforebegin" and "afterend" insert into the element’s parent. Browser support is basically universal.
    • insertAdjacentText is just like insertAdjacentHTML except that it inserts a text node (the text is not treated as HTML). Browser support is basically universal.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 357k
  • Answers 357k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer The other answers are correct. Here is some code you… May 14, 2026 at 9:40 am
  • Editorial Team
    Editorial Team added an answer you ruin the noConflict concept by reassigning the jquery to… May 14, 2026 at 9:40 am
  • Editorial Team
    Editorial Team added an answer If you get that particular error, you don't actually have… May 14, 2026 at 9:40 am

Related Questions

No related questions found

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.