Javascript examples for DOM HTML Element:Label
The form property returns the form containing the label.
This property is read only.
A reference to the form element containing the label. If the label is not in a form, null is returned
The following code shows how to return the id of the form containing the <label> element:
<!DOCTYPE html> <html> <body> <form id="myForm"> <label id="myLabel" for="male">Male</label> <input type="radio" name="sex" id="male" value="male"><br> </form>/* w w w . ja v a 2 s . c o m*/ <p id="demo"></p> <button onclick="myFunction()">Test</button> <script> function myFunction() { var x = document.getElementById("myLabel").form.id; document.getElementById("demo").innerHTML=x; } </script> </body> </html>