Document getElementsByName() Method - Find out how many elements in the document with a name attribute = animal - Javascript DOM

Javascript examples for DOM:Document getElementsByName

Description

Document getElementsByName() Method - Find out how many elements in the document with a name attribute = animal

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>
Cats:/* w  w  w  .j a  v  a  2 s  .c  om*/
<input name="animal" type="checkbox" value="Cats">
Dogs:
<input name="animal" type="checkbox" value="Dogs">

<button onclick="myFunction()">Test</button>

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

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

</body>
</html>

Related Tutorials