Javascript examples for DOM:Document getElementsByName
Document getElementsByName() Method - Find out how many elements in the document with a name attribute = animal
<!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>