CKTIS / JavaScript
Element.id — element identifier
Element.id reads and changes a DOM element’s id attribute. A missing attribute produces an empty string.
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
element.id
element.id = "panel";Element.id is a writable string property reflecting the id attribute. Assigning the property changes the attribute; changing the attribute through setAttribute() is visible when reading the property.
A missing attribute and id="" produce the same property value: "". Use hasAttribute("id") to distinguish them. Assigning "" does not remove the attribute — use removeAttribute("id"). In either case, the element has no DOM identifier. The example uses a detached element without changing the page.
Examples
const element = document.createElement("div");
console.log(JSON.stringify(element.id));
element.id = "panel";
console.log(element.getAttribute("id"));
element.setAttribute("id", "details");
console.log(element.id);
element.id = "";
console.log(element.hasAttribute("id"));
element.removeAttribute("id");
console.log(element.hasAttribute("id"));Result
"" panel details true false
The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.