Skip to content
geeksforgeeks
  • Tutorials
    • Python
    • Java
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
    • Practice Coding Problems
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • HTML Tutorial
  • HTML Exercises
  • HTML Tags
  • HTML Attributes
  • Global Attributes
  • Event Attributes
  • HTML Interview Questions
  • HTML DOM
  • DOM Audio/Video
  • HTML 5
  • HTML Examples
  • Color Picker
  • A to Z Guide
  • HTML Formatter
Open In App
Next Article:
HTMLCollection item() Method
Next article icon

HTMLCollection item() Method

Last Updated : 10 Aug, 2022
Comments
Improve
Suggest changes
Like Article
Like
Report

The item() method is used to return the content of element at the given index of the collection of all HTML element. The index starts from zero(0). The elements in the collection are sorted in the order as they appear in the sourcecode. 

Syntax:

HTMLCollection.item(index) 

OR

HTMLCollection[index] 

Parameters: It contains a number that represents the index of the element that the user wants to return. The index starts from 0.

Example-1: 

html
<!DOCTYPE html> <html>  <head>     <style>         h1 {             color: green;         }     </style> </head>  <body>     <center>         <h1>GeeksForGeeks</h1>         <h2>HTMLCollection item() Method</h2>          <button onclick="Geeks()">Submit</button>          <script>             function Geeks() {                 var w = document.getElementsByTagName("h1");                 alert(w.item(0).innerHTML);             }         </script>  </body>  </html> 

Output: 

Before clicking on the button: 

 

After clicking on the button:

  

Example-2: To change the content of an HTML Element. 

html
<!DOCTYPE html> <html>  <head>     <style>         h1 {             color: green;         }     </style> </head>  <body>     <center>         <h1>GeeksForGeeks</h1>         <h2>HTMLCollection item() Method</h2>         <p>geeforgeefs</p>         <button onclick="Geeks()">Submit</button>          <script>             function Geeks() {                 document.getElementsByTagName("P")[0].innerHTML =                                                    "GeeksForGeeks";             }         </script>  </body>  </html> 

Output: 

Before clicking on the button:

  

After clicking on the button:

  

Supported Browsers: The browser supported by HTMLCollection item() Method are listed below:

  • Google Chrome 1
  • Edge 12
  • Internet Explorer 8
  • Firefox 1
  • Opera 12.1
  • Safari 1

Next Article
HTMLCollection item() Method

M

manaschhabra2
Improve
Article Tags :
  • Misc
  • Web Technologies
  • HTML
  • HTML-Methods
Practice Tags :
  • Misc

Similar Reads

    HTML DOM Table tBodies Collection
    The Table tBodies collection is used for returning the collection of all the <tbody> elements in a table. The sequence of the <body> elements are sorted in the same way as their position in the source code. Syntax:tableObject.tBodiesProperties:length: It returns the number of <tbody
    2 min read
    HTML Collection for Loop
    An HTMLCollection for loop is used to iterate over a collection of HTML elements, like those returned by getElementsByTagName() or getElementsByClassName(). Use a for loop, for...of the loop, or convert the collection to an array with Array.from() for easy iteration.Note: It is not recommended to us
    4 min read
    HTML DOM forms Collection
    The DOM forms collection is used to return the collection of all <form> elements in a HTML document. The form elements are sorted as they appear in the source code. Syntax: document.forms Properties: It returns the number of form in the collection of elements. Methods: The DOM forms collection
    4 min read
    Nested List in HTML
    A nested list in HTML is a list that contains other lists within its list items. This creates a hierarchical structure, where each sublist is indented to visually represent its relationship to the parent list item. 1. Nested Unordered List in HTMLAn unordered list in HTML is a collection of items re
    1 min read
    HTML DOM Form elements Collection
    The Form element collection in HTML DOM is used to set or return the collection of all <input> elements inside a form element. The <input> elements are sorted as they appear in the source code. Syntax: formObject.elements Properties: It returns a number of input elements inside the <f
    2 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences