Categories
JavaScript Answers

How to get the pure text without HTML element using JavaScript?

Spread the love

To get the pure text without HTML element using JavaScript, we can use the textContent property.

For instance, we write

const element = document.getElementById("txt");
const text = element.textContent;

to select the element with getElementById.

And then we get the textContent property to get the pure text inside the element.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *