Javascript examples for DOM HTML Element:Label
Label htmlFor Property - Change the value of the value attribute of a label:
<!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>