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 should load the label before we change its content.

For instance, we write

<label id="lbltipAddedComment">test</label>
<script>
  document.getElementById("lbltipAddedComment").innerHTML =
    "your tip has been submitted!";
</script>

to add the label element before the script element.

Then we select the label with getElementById.

And then we set its innerHTML property to the content we want.

Conclusion

To change label text using JavaScript, we should load the label before we change its content.

Leave a Reply

Your email address will not be published. Required fields are marked *