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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T12:02:05+00:00 2026-06-17T12:02:05+00:00

I know how to do this with jQuery, but I want to learn it

  • 0

I know how to do this with jQuery, but I want to learn it with vanilla javascript, I have a feeling it’ll be faster. Here’s a link to jsFiddle with a stripped down version of what I’m trying to do. http://jsfiddle.net/yramagicman/MyM2B/ and below is the offending script.

<script>
var id = 'ul';
var tag = 'li';
var wrapTag = 'span';
var wrapper = document.createElement(wrapTag);
var z = document.getElementById(id);
var y = z.getElementsByTagName(tag);
var count = y.length;
for (var i = 0; i < count; i++) {
    y[i].setAttribute("class", "red"); //so I can see the result
    wrapper.appendChild(y[i].cloneNode(true));
    y[i].parentNode.replaceChild(wrapper, y[i]);
    wrapper.setAttribute('class', 'hi'); //so I can see the result
}</script>
<!-- and the html-->
<ul id="ul" class="ul">
    <li class="li">1</li>
    <li class="li">2</li>
    <li class="li">3</li>
    <li class="li">4</li>
    <li class="li">5</li>
    <li class="li">6</li>
    <li class="li">7</li>
    <li class="li">8</li>
</ul>

I can wrap the entire Ul in a div or span or whatever just fine but when I try to wrap each list item I get the error “HIERARCHY_REQUEST_ERR: DOM Exception 3: A Node was inserted somewhere it doesn’t belong.” Any ideas?

  • 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-06-17T12:02:07+00:00Added an answer on June 17, 2026 at 12:02 pm

    You are building an invalid DOM. <li> must belong in <ul> or <ol> but you’re trying to place it in a <span>. Hence the error: “A Node was inserted somewhere it doesn’t belong”.

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

Sidebar

Related Questions

I know how I would achieve this using PHP, but with jQuery / JavaScript
I'm not using JQuery but I know they have functions to do this. I
I know this question is quite basic but I am new to JQuery and
I'm using this jQuery inline datePicker plugin sample but I don't know how to
Do browser vendors optimize against jQuery? I know this sounds absurd anti-standard, but I
I know it's possible with jQuery, but I'm having some serious troubles with this
I know there exists a command like jQuery.noConflict. But for this it first registers
I don't know if anyone ELSE has noticed this, but I noticed the jQuery
I have this JQuery code working however I need to know whether how to
I'm new to jQuery (or all things javascript, really) but know my way around

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.