Javascript examples for DOM HTML Element:Label
The Label object represents an HTML <label> element.
You can access a <label> element by using getElementById():
<!DOCTYPE html> <html> <body> <label id="myLabel" for="male">Male</label> <input type="radio" name="sex" id="male" value="male"><br> <button onclick="myFunction()">get the id of the element the label is bound to</button> <p id="demo"></p> <script> function myFunction() {/* w ww.j a va 2s.c om*/ var x = document.getElementById("myLabel").htmlFor; document.getElementById("demo").innerHTML = x; } </script> </body> </html>