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 some html like the following: <div class=control-group> <input type=text data-bind=value: $data.DealCode name=DealCode
I have the following HTML like <body> <div class=myCool>blah</div> <div class=cool>some text</div> <div class=cool>some
I have a html file like following: <form action=/2811457/follow?gsid=3_5bce9b871484d3af90c89f37 method=post> <div> <a href=/2811457/follow?page=2&amp;gsid=3_5bce9b871484d3af90c89f37>next_page</a> &nbsp;<input
So I have some html that looks like the following: <div class='something unknown' id='something_unknown_1'>
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>
I have some HTML with the following approximate structure and positioning: <div class=grand-parent style=position:
Imagine you have two views with code like the following: controller_a/a.html.erb <%= content_tag(:div) do
I have the following HTML: <div id=mydiv> </div> I would like to load content
I would like to have the following kind of HTML: <header></header> <div id='main'></div> <footer></footer>

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.