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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T12:20:44+00:00 2026-05-29T12:20:44+00:00

How can you change this <div id=’myDiv’><p>This div has <span>other elements</span> in it.</p></div> into

  • 0

How can you change this

<div id='myDiv'><p>This div has <span>other elements</span> in it.</p></div>

into this

<div id='myDiv'>This div has other elements in it.</div>

hopefully using something like this

var ele = document.getElementById('myDiv');
while(ele.firstChild) {
    replaceFunction(ele.firstChild, ele.firstChild.innerHTML);
}
function replaceFunction(element, text) {
    // CODE TO REPLACE ELEMENT WITH TEXT
}
  • 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-29T12:20:45+00:00Added an answer on May 29, 2026 at 12:20 pm

    You can use innerText and textContent if you want to remove all descendant nodes, but leave the text:

    // Microsoft
    ele.innerText = ele.innerText;
    // Others
    ele.textContent = ele.textContent;
    

    If you only want to flatten certain ones, you can define:

    function foldIntoParent(element) {
      while(ele.firstChild) {
        ele.parentNode.insertBefore(ele.firstChild, ele);
      }
      ele.parentNode.removeChild(ele);
    }
    

    should pull all the children out of ele into its parent, and remove ele.

    So if ele is the span above, it will do what you want. To find and fold all the element children of #myDiv do this:

    function foldAllElementChildren(ele) {
      for (var child = ele.firstChild, next; child; child = next) {
        next = child.nextSibling;
        if (child.nodeType === 1 /* ELEMENT */) {
          foldIntoParent(child);
        }
      }
    }
    
    foldAllElementChildren(document.getElementById('myDiv'));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can someone tell me how to change directories using FtpWebRequest? This seems like it
You can change the connection string at run-time like this. You make the connection
How can I change the master volume level? Using this code [DllImport (winmm.dll)] public
The HTML looks something like this: <li class=divider> <div> ...(maybe more divs)... <div class=content>
Can i change this code to somethign like the below code? <style> .FirstLetter:first-letter{font-family: arial;
In PHPStorm 3.0, a PHP string like: $sString = '<div><span class=someClass>test</span></div>'; has HTML Syntax
Hi have a div that's wrapping images..The width of this DIV can change so
I can set data in JTable constructor, and then user can change this data
(r'^/(?P<the_param>[a-zA-z0-9_-]+)/$','myproject.myapp.views.myview'), How can I change this so that the_param accepts a URL(encoded) as a
According to this website , you can change to command key sequence used by

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.