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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T03:50:26+00:00 2026-05-16T03:50:26+00:00

I have HTML like the following: <div id=move-me> <a href=#>I’m a link</a> </div> <div

  • 0

I have HTML like the following:

<div id="move-me">
    <a href="#">I'm a link</a>
</div>

<div id="new-parent">
    Some plain text.
</div>

I’m trying to write JavaScript that will move the entire #move-me div inside the #new-parent div, above the text, like so:

<div id="new-parent">
    <div id="move-me">
        <a href="#">I'm a link</a>
    </div>
    Some plain text.
</div>

Here’s the JavaScript I have:

function moveDiv() {
    var moveable = document.getElementById('move-me');
    var newParent = document.getElementById('new-parent');
    newParent.parentNode.insertBefore(moveable, newParent.firstChild);
}

I’m using Firebug to debug, and I can see that newParent.firstChild is a TextNode, but I always receive the following error:

Node was not found" code: "8
newParent.parentNode.insertBefore(moveable, newParent.firstChild); 

It seems like insertBefore requires an element node and won’t work on a text node… is that right? If so, is there another good method for doing this?

Note: I can’t modify or clean up the HTML to include paragraph tags or remove white space.

  • 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-16T03:50:27+00:00Added an answer on May 16, 2026 at 3:50 am

    No, insertBefore will work fine with a text node as the node to be inserted before. The problem is that the node you’re trying to insert before is not a child of the node you’re inserting into. You need to remove the .parentNode bit:

    newParent.insertBefore(moveable, newParent.firstChild); 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following HTML like <body> <div class=myCool>blah</div> <div class=cool>some text</div> <div class=cool>some
I have html like so: <div class=foo> (<a href=forum.example.com>forum</a>) <p> Some html here.... </div>
I have a html like this: <html> <head> <link rel=stylesheet type=text/css media=all href=style.css> </head>
i have html code that looks like the following: String html = <html><head><style type=\text/css\></style></head><body><div
Say I have the following HTML: <div> <span>span text</span> div text <span>some more text</span>
So I have some html that looks like the following: <div class='something unknown' id='something_unknown_1'>
I have the following HTML: <div id=mydiv> </div> I would like to load content
I have HTML code like this : <div> <a>Link A1</a> <a>Link A2</a> <a>Link A3</a>
I have something like following <a class=item href=a.htm> <div class=title>abcd</div> <div class=body>abcd</div> </a> with
I have some HTML that looks like this: <div class=MyClass></div> <div class=MyClass></div> <div class=MyClass></div>

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.