Label form Property - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Label

Description

The form property returns the form containing the label.

This property is read only.

Return Value

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:

Demo Code

ResultView the demo in separate window

<!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>

Related Tutorials