Categories
JavaScript Answers

How to change label text using JavaScript?

Spread the love

Sometimes, we want to change label text using JavaScript.

In this article, we’ll look at how to change label text using JavaScript.

How to change label text using JavaScript?

To change label text using JavaScript, we can select the label and set its innerHTML property.

For instance, we write

<label id="lbltipAddedComment">test</label>

to add a label element.

Then we write

document.getElementById("lbltipAddedComment").innerHTML = "success!";

to select the label with getElementById.

Then we set its innerHTML property to the label text we want.

We should run the JavaScript code after the label element is loaded.

Conclusion

To change label text using JavaScript, we can select the label and set its innerHTML 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 *