Label htmlFor Property - Change the value of the value attribute of a label: - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Label

Description

Label htmlFor Property - Change the value of the value attribute of a label:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<form>
  <label id="myLabel" for="male">Male</label>
  <input type="radio" name="sex" id="male" value="male"><br>
</form>//from   ww  w.j av  a2s .  co  m

<button onclick="myFunction()">Test</button>

<p id="demo"></p>

<script>
function myFunction() {
    document.getElementById("myLabel").htmlFor = "newValue";
    document.getElementById("demo").innerHTML = "The value of the for attribute was changed from 'male' to 'newValue'.";
}
</script>

</body>
</html>

Related Tutorials