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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T20:07:14+00:00 2026-06-11T20:07:14+00:00

i have for example this: <td class=name> <span class=removed>one</span> <span class=added>two</span> </td> or this:

  • 0

i have for example this:

<td "class=name">
    <span class="removed">one</span>
    <span class="added">two</span>
</td>

or this:

<td class=name> one
    <span class="removed">two</span>
    <span class="added">three</span>
</td>

or this:

<div>
    one
    <span class="added">two</span>
    three four 
    <span class="removed">five</span>
    six
</div>

and want to change it with JavaScript (without JQuery) to this:

<td "class=name">
    two
</td>

or this:

<td class=name> 
    one
    three
</td>

or this:

<div>
    one
    two
    three
    four
    six
</div>

can’t figure it out. and only found a lot of jquery stuff like replaceWith and so on, but need pure javascript for it

  • 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-11T20:07:15+00:00Added an answer on June 11, 2026 at 8:07 pm

    If all the span tags you have that you want removing have a class of removed or added and testing them using the class doesn’t affect any of your other html you could try this.

    var spans = document.getElementsByTagName("span");
    
    for(var i=0; i<spans.length;i++)
    {
      if(spans[i].className == "added")
      {
         var container = spans[i].parentNode;
         var text = spans[i].innerHTML;
         container.innerHTML += text;
         container.removeChild(spans[i]);
      }
      else if(spans[i].className == "removed")
      {
          var container = spans[i].parentNode;
          container.removeChild(spans[i]);
      }
    }
    

    Otherwise you need to find a way by ID or class name perhaps to grab the container of the span tags and do something similar. For instance like this

    var myDiv = document.getElementById("myDiv");
    var spans = myDiv.getElementsByTagName("span");   
    
    for(var i=0; i<spans.length;i++)
    {
      if(spans[i].className == "added")
      {
         var text = spans[i].innerHTML;
      }
      myDiv.innerHTML += text;
      myDiv.removeChild(spans[i]);
    }
    

    Hope this helps

    EDIT

    Try here for an idea of how to implement this code using a getElementsByClassName() function which might simplify this. It returns an array like getElementsByTagName() does which you can iterate over.

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

Sidebar

Related Questions

I have the following XPath to match authors name in an Amazon page: //div[@class='pTitle']/span[@class='small
If I have a string that contains this. Hi my name is <span class=name>Joe</span>.
I have this example: public class Inheritance { public static class Animal { public
For example, i have this: class BasePacket { int header; int type; } class
I have this simple example: using System; using System.Collections.Generic; namespace ConsoleApplication1 { class Program
Say I have a class ObjectA (a view controller for example), that does this
Before Consider to have a class and a global function: This is, for example,
I have the following markup for my input fields: <div class=required> <label for=Name>Name <em>*</em></label>
I was wondering, i have this HTML : <li> <span class=jqTransformRadioWrapper> <a rel=choices[choices] class=jqTransformRadio
I have two user models one is 1. User.rb (this is my own authentication

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.