Example 1 — Read document.body.id (MDN)
Given <body id="oldBodyElement">, read the id from JavaScript.
// HTML: <body id="oldBodyElement">…</body>
console.log(document.body.id); // "oldBodyElement"
console.log(document.body.tagName); // "BODY" How It Works
- Body is an element — same DOM API as any other node.
- Read
idfrom the attribute on<body>. - Read
tagName— usually"BODY"in HTML documents. - No mutation — this example only inspects.

