How to count the number of HTML elements with the same tag name in a document with JavaScript

1 Answer

0 votes
<!DOCTYPE html>
<html>
<head>
<script>
function TotalElements() {
  var el = document.getElementsByTagName("input");
  document.getElementById("pid").innerHTML = el.length;
}
</script>
</head>
<body>

A: <input type="radio" value="A">
B: <input type="radio" value="B">
C: <input type="radio" value="C">

<br /><br />
<input type="button" onclick="TotalElements()" value="Total Elements">

<p id="pid"></p>

</body>
</html>

 



answered Jan 12, 2019 by avibootz
...