Sometimes, we want to get the text of a div tag using only JavaScript.
In this article, we’ll look at how to get the text of a div tag using only JavaScript.
How to get the text of a div tag using only JavaScript?
To get the text of a div tag using only JavaScript, we can use the textContent
property.
For instance, we write
const el = document.getElementById("foo");
const textContent = el.textContent;
to select the element with getElementById
.
Then we get the text of the element with the textContent
property.
Conclusion
To get the text of a div tag using only JavaScript, we can use the textContent
property.