How to change label text using JavaScript?

Spread the love

To change label text using JavaScript, we set the innerHTML property.

For instance, we write

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

to add a label element.

Then we write

document.getElementById("lbltipAddedComment").innerHTML =
  "your tip has been submitted!";

to select the element with getElementById.

And then we set innerHTML property with the new label text to update it.

Leave a Reply

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