![Trending Articles on Technical and Non Technical topics](/images/trending_categories.jpeg)
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- 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 item( ) Method
The HTML DOM item() method returns a node from a node list object.
Note − The item() method is used to provide index value in a node list object. It is same as getting node by passing index value in ‘[index]’ on node list object.
Syntax
Following is the syntax −
Calling item(index), where index starts from 0
nodeListObject.item(index)
Example
Let us see an example for item() method −
<!DOCTYPE html> <html> <head> <title>item()</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>item( )</legend> <h2>Menu</h2> <ul> <li onclick="getOrder(0)">Mac & Cheese</li> <li onclick="getOrder(1)">Pizza</li> <li onclick="getOrder(2)">Burger</li> </ul> <div id="divDisplay">Click on menu item to order it</div> </fieldset> </form> <script> var divDisplay = document.getElementById("divDisplay"); var menuSelect = document.getElementsByTagName("li"); function getOrder(index) { divDisplay.textContent = 'Order: '+(menuSelect.item(index)).textContent; } </script> </body> </html>
Output
This will produce the following output −
Before clicking ‘<li>’ element −
After clicking ‘<li>’ element −
Advertisements