Syamsoul Azrien
Syamsoul Azrien

Reputation: 2742

Get innerHTML value - only plain text

This is what i'm gonna do...

alert(document.getElementById('test').innerHTML);
<div id="test">
  hi..my name is <div>Soul</div> and I am <strong>23 years old</strong>
  Thank you.
</div>

The alert box will show this:

hi..my name is <div>Soul</div> and I am <strong>23 years old</strong>Thank you.

But what I want inside the ALERT BOX is:

hi..my name is Soul and I am 23 years old Thank you.

Upvotes: 3

Views: 3367

Answers (1)

Pranav C Balan
Pranav C Balan

Reputation: 115202

Use textContent instead of innerHTML for getting text content instead of markup

console.log(document.getElementById('test').textContent);
<div id="test">
  hi..my name is <div>Soul</div> and I am <strong>23 years old</strong>
  Thank you.
</div>

Upvotes: 5

Related Questions