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

Sometimes, we want to get the pure text without HTML element using JavaScript.

In this article, we’ll look at how to get the pure text without HTML element using JavaScript.

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

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

For instance, we write

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

to select the element with getElementById.

And then we use the innerText or textContent properties to get the text content of the element.

Conclusion

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