CKTIS / JavaScript
document.getElementById — find an element by ID
document.getElementById(elementId) returns the element with the specified ID or null. Matching is case-sensitive and searches the document’s descendants.
Version: ECMAScript and Web APIs; exact feature edition and browser support reviewed per entry; Node 24 in repository does not prove browser API support
Syntax
document.getElementById(elementId)document.getElementById(elementId) is a DOM method, not part of ECMAScript itself. Pass an id value such as "status", without a # prefix: the argument is not a CSS selector. The result is an Element or null. Matching is case-sensitive; an empty identifier does not match.
The method searches the document’s descendants. A detached element will not be found. With duplicate IDs, it returns the first element in tree order, not necessarily the first created. Check for null before using the result; perform the lookup only after the target element has been added to the document.
getElementById is also available on DocumentFragment, but not on ordinary Element objects. Document lookup does not enter shadow trees. The example requires a browser DOM environment; a Node.js version alone does not establish support for this API.
Examples
{
const document = globalThis.document.implementation.createHTMLDocument("");
const item = document.createElement("div");
item.id = "status";
console.log(document.getElementById("status") === null);
document.body.appendChild(item);
console.log(document.getElementById("status") === item);
console.log(document.getElementById("Status") === null);
item.remove();
console.log(document.getElementById("status") === null);
}Result
true true true true
The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.