Edit This Code:
<!DOCTYPE html>
<html>
<body>

<h3>A demonstration of how to access a LABEL element</h3>

<label id="myLabel" for="male">Male</label>
<input type="radio" name="sex" id="male" value="male"><br>

<p>Click the button to get the id of the element the label is bound to.</p>

<button onclick="myFunction()">Try it</button>

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

<script>
function myFunction() {
    var x = document.getElementById("myLabel").htmlFor;
    document.getElementById("demo").innerHTML = x;
}
</script>

</body>
</html>


Result:
Try it Yourself - © w3schools.com
Privacy Policy