Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
HTML DOM length Property
The HTML DOM length property returns a number corresponding to the nodes in node list object.
Syntax
Following is the syntax −
Returning number of nodes in nodeList Object.
nodeList.length
Example
Let us see an example for HTML DOM length property −
<!DOCTYPE html>
<html>
<head>
<title>HTML DOM length</title>
<style>
form {
width:70%;
margin: 0 auto;
text-align: center;
}
* {
padding: 2px;
margin:5px;
}
input[type="button"] {
border-radius: 10px;
}
ul{
width: 30%;
margin: 0 auto;
}
</style>
</head>
<body>
<form>
<fieldset>
<legend>HTML-DOM-length</legend>
<h3>Students</h3>
<ul>
<li>Adam</li>
<li>Alex</li>
<li>Bina</li>
<li>Eden</li>
<li>Rajesh</li>
<li>Zampa</li>
</ul>
<input type="button" onclick="getStrength()" value="Get Total Students">
<div id="divDisplay"></div>
</fieldset>
</form>
<script>
var divDisplay = document.getElementById("divDisplay");
var studentList = document.getElementsByTagName("li");
function getStrength() {
divDisplay.textContent = 'Total Students: '+studentList.length;
}
</script>
</body>
</html>
Output
This will produce the following output −
Before clicking ‘Get Total Students’ button −

After clicking ‘Get Total Students’ button −

Advertisements