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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T22:24:42+00:00 2026-05-23T22:24:42+00:00

I have the 1 button and some text in my HTML like the following:

  • 0

I have the 1 button and some text in my HTML like the following:

function get_content(){
   // I don't know how to do in here!!!
}

<input type="button" onclick="get_content()" value="Get Content"/>
<p id='txt'>
<span class="A">I am</span>
<span class="B">working in </span>
<span class="C">ABC company.</span>
</p>

When the user clicks the button, the content in the <p id='txt'> will become the follow expected result:

<p id='txt'>
// All the HTML element within the <p> will be disappear
I am working in ABC company.
</p>

Can anyone help me how to write the JavaScript function?

Thank you.

  • 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-23T22:24:43+00:00Added an answer on May 23, 2026 at 10:24 pm

    [2017-07-25] since this continues to be the accepted answer, despite being a very hacky solution, I’m incorporating Gabi‘s code into it, leaving my own to serve as a bad example.

    // my hacky approach:
    function get_content() {
      var html = document.getElementById("txt").innerHTML;
      document.getElementById("txt").innerHTML = html.replace(/<[^>]*>/g, "");
    }
    // Gabi's elegant approach, but eliminating one unnecessary line of code:
    function gabi_content() {
      var element = document.getElementById('txt');
      element.innerHTML = element.innerText || element.textContent;
    }
    // and exploiting the fact that IDs pollute the window namespace:
    function txt_content() {
      txt.innerHTML = txt.innerText || txt.textContent;
    }
    .A {
      background: blue;
    }
    
    .B {
      font-style: italic;
    }
    
    .C {
      font-weight: bold;
    }
    <input type="button" onclick="get_content()" value="Get Content (bad)" />
    <input type="button" onclick="gabi_content()" value="Get Content (good)" />
    <input type="button" onclick="txt_content()" value="Get Content (shortest)" />
    <p id='txt'>
      <span class="A">I am</span>
      <span class="B">working in </span>
      <span class="C">ABC company.</span>
    </p>
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a textbox and a link button. When I write some text, select
I'd like to have a TabNavigator component that has a close button for some
I need some advanced CSS help here. I have a login button and a
I am creating an HTML form with some radio button options. I'd like to
I'm trying to do this: into html so when I type some text the
Suppose i have the following html: <button class=inforTextButton idmyButton> <span class=leftSlice></span> <span class=centerSlice>Approved</span> <span
I want to use: HTML 5 Required. such as <input type='text' required> it only
I would like to put a button inside text like this one: some text1
I'm working on a little project, basically I have some text on my PHP/HTML
Consider the following HTML. If I have a JSON reference to the <button> element,

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.