 
  Data Structure Data Structure
 Networking Networking
 RDBMS RDBMS
 Operating System Operating System
 Java Java
 MS Excel MS Excel
 iOS iOS
 HTML HTML
 CSS CSS
 Android Android
 Python Python
 C Programming C Programming
 C++ C++
 C# C#
 MongoDB MongoDB
 MySQL MySQL
 Javascript Javascript
 PHP 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
How to return the id of the first image in a document with JavaScript?
To return the id of the first image, use the images property in JavaScript.
Example
You can try to run the following code to return the id of the first image in a document −
<!DOCTYPE html> <html>    <body>       <img id="image1" src="https://www.tutorialspoint.com/html5/images/html5-mini-logo.jpg">       <img id="image2" src="https://www.tutorialspoint.com/hive/images/hive-mini-logo.jpg">       <img id="image3" src="https://www.tutorialspoint.com/sas/images/sas-mini-logo.jpg">       <img id="image4" src="https://www.tutorialspoint.com/maven/images/maven-mini-logo.jpg">       <script>          var val = document.images.length;          document.write("<br>Number of images in the document: "+val);          document.write("<br>The id of the first image: "+document.images[0].id);       </script>    </body> </html>Advertisements
 