You assign a label to an element using as in the example
<p>Name: <label id="lblName"></label></p>
- Since a label is simple html tag that has no value, reading and writing the value of a label can be a difficult proposition. Labels are a bit odd when compared to other form fields.
In order to read or write the value of a label you have to use the
Here is an example of setting a label:
document.getElementById("lblName").innerHTML = "Fred";And here is an example of reading the value of a label:
var myName = document.getElementById("lblName").innerHTML;
- Only use InnerHTML with labels!