परिचय
HTML DOM images कलेक्शन प्रॉपर्टी HTML दस्तावेज़ में सभी <img> एलिमेंट्स का कलेक्शन लौटाती है।
सिंटैक्स
document.images
प्रॉपर्टी
| प्रॉपर्टी | व्याख्या |
|---|---|
| length | HTML दस्तावेज़ में <img> एलिमेंट्स की संख्या लौटाता है। |
मेथड्स
| मेथड | व्याख्या |
|---|---|
| [index] | कलेक्शन से निर्दिष्ट इंडेक्स का <img> एलिमेंट लौटाता है। |
| item(index) | कलेक्शन से निर्दिष्ट इंडेक्स का <img> एलिमेंट लौटाता है। |
| namedItem(id) | कलेक्शन से निर्दिष्ट ID का <img> एलिमेंट लौटाता है। |
उदाहरण
पेज पर इमेजेज की संख्या गिनना:
<!DOCTYPE html>
<html>
<head>
<style>
body { text-align: center; }
.btn {
background-color: lightblue;
border: none;
height: 2rem;
border-radius: 50px;
width: 60%;
margin: 1rem auto;
display: block;
}
.show { color: #db133a; font-size: 2rem; font-weight: bold; }
</style>
</head>
<body>
<h1>DOM इमेज ऑब्जेक्ट उदाहरण</h1>
<img src="https://www.tutorialspoint.com/spring/images/spring-mini-logo.jpg" alt="Learn Spring">
<img src="https://www.tutorialspoint.com/hibernate/images/hibernate-mini-logo.jpg" alt="Learn Hibernate">
<img src="https://www.tutorialspoint.com/sql/images/sql-mini-logo.jpg" alt="Learn SQL">
<img src="https://www.tutorialspoint.com/plsql/images/plsql-mini-logo.jpg" alt="Learn PL/SQL">
<button onclick="getCount()" class="btn">इमेजेज की संख्या गिनें</button>
<div class="show"></div>
<script>
function getCount() {
document.querySelector('.show').innerHTML = document.images.length;
}
</script>
</body>
</html>
आउटपुट
"इमेजेज की संख्या गिनें" बटन पर क्लिक करने पर पेज पर मौजूद इमेजेज की कुल संख्या (4) प्रदर्शित होगी।