Sometimes, we want to get value of span text with JavaScript.
In this article, we’ll look at how to get value of span text with JavaScript.
How to get value of span text with JavaScript?
To get value of span text with JavaScript, we use the innerText
property.
For instance, we write
<span id="span_Id">I am the Text </span>
to add a span.
Then we write
const spanText = document.getElementById("span_Id").innerText;
console.log(spanText);
to select the span with getElementById
.
Then we get the text content with the innerText
property.
Conclusion
To get value of span text with JavaScript, we use the innerText
property.