Categories
JavaScript Answers

How to get value of span text with JavaScript?

Spread the love

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.

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 *