Home JavaScript NodeList Methods item() JavaScript NodeList item() Method Definition NodeList.item() returns one node by zero-based index (MDN) . Out of range returns null — it does not throw when you pass an argument.
Pass the required arguments shown below. Check return values and browser support before you rely on the result.
Syntax Call nodeList.item. Start with this line.
Call What it does nodeList.item(index)Primary signature. nodeList.item(...)Call with the arguments your case needs.
Built into the browser. Call item(...) on a NodeList — no import required.
Library declarations Parameters Parameter Description index Required. Zero-based position
Return Value Return Value Description * The node at that index * null
JavaScript Examples 1. Basic item(0) 2. Second node 3. Out of range 4. vs brackets 5. Loop with length Example 1 — Basic item(0) Read the first child node by index.
const node = document.createElement("div");
node.appendChild(document.createElement("p"));
node.appendChild(document.createElement("span"));
const first = node.childNodes.item(0);
console.log(first.nodeName); // P How It Works Create a parent. Append two element children.Call item(0). Index 0 is the first node.Read nodeName. Confirms you got the <p>.Tip. Same idea as list[0] in JavaScript.Example 2 — Second Node MDN idea: item(1) returns the second entry (zero-based).
// Imagine: <ul id="fruit"><li>Apple</li><li>Banana</li><li>Cherry</li></ul>
const list = document.querySelectorAll("#fruit li");
const second = list.item(1);
console.log(second.textContent); // Banana How It Works Select list items. querySelectorAll returns a NodeList.Call item(1). Second item — not the first.Read text. Banana is at index 1.Static list. Unlike live childNodes, this snapshot does not grow later.Example 3 — Out of Range An index past the end returns null, not an exception.
const node = document.createElement("div");
node.appendChild(document.createElement("p"));
const list = node.childNodes;
const missing = list.item(5);
console.log(missing); // null
console.log(missing === null); // true How It Works One child only. Valid indexes are 0 alone.Call item(5). Past the end.Get null. Safe to check before use.No throw. MDN: exceptions are avoided when an argument is provided.Example 4 — vs Brackets In JavaScript, list[i] reads the same node — missing values differ.
const node = document.createElement("div");
node.appendChild(document.createElement("p"));
const list = node.childNodes;
console.log(list.item(0).nodeName); // P
console.log(list[0].nodeName); // P
console.log(list.item(9)); // null
console.log(list[9]); // undefined How It Works In range. item(0) and list[0] match.Out of range. item → null; brackets → undefined.Pick a check. Use === null with item, or truthy checks carefully.Why item? Useful in non-JS DOM APIs; clear method name in tutorials.Example 5 — Loop with length Classic index loop: item(i) from 0 to length - 1.
const node = document.createElement("div");
node.appendChild(document.createElement("p"));
node.appendChild(document.createTextNode("hey"));
node.appendChild(document.createElement("span"));
const list = node.childNodes;
const names = [];
for (let i = 0; i < list.length; i++) {
names.push(list.item(i).nodeName);
}
console.log(names.join(", ")); // P, #text, SPAN How It Works Use length. Upper bound for the loop.Call item(i). Safe while i < length.Collect names. Same order as insertion.Modern tip. Prefer forEach() or for...of for everyday walks.Compatibility
Browser Support NodeList.item() is marked Baseline Widely available on MDN (since July 2015). DOM API — not a Node.js built-in.
✓ Baseline · Widely available
item() Read a NodeList entry by zero-based index across modern browsers.
Chrome 1+
Full support
Edge 12+
Full support
Firefox Yes
Full support
Safari Yes
Full support
Opera Yes
Full support HTML element 100% supported
Bottom line: Safe for production. Prefer item(i) or list[i] for one node; use forEach / for...of for full walks.
Frequently Asked Questions What does NodeList.item() do? It returns the node at a zero-based index in the NodeList. If the index is out of range, it returns null.
Is item() deprecated or experimental? No. MDN marks NodeList.item() as Baseline Widely available (since July 2015). It is not Deprecated, Experimental, or Non-standard.
Can I use nodeList[index] instead? Yes in JavaScript. MDN notes that nodeList[index] is equivalent for reading a node. One difference: out of range, item() returns null while brackets return undefined.
What if the index is too large? item(index) returns null. It does not throw for an out-of-range index (as long as you did provide an argument).
What if I call item() with no argument? A TypeError is thrown when no argument is provided.
Is the index zero-based? Yes. item(0) is the first node; item(1) is the second.
Next: keys() Iterate only the indexes of a NodeList.
keys() → About the author Developer, cloud engineer, and technical writer
I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.
8 people found this page helpful
Helpful Share Copy link Suggestion