Document.body — accessing the document's body element
Document.body is a Web API property accessed as document.body. It returns a body element, a legacy frameset element, or null. Assignment replaces the entire element, not just its contents.
CKTIS / JavaScript
Programming syntax, operators and concepts. Find an explanation, explore an example and return to learning.
Document.body is a Web API property accessed as document.body. It returns a body element, a legacy frameset element, or null. Assignment replaces the entire element, not just its contents.
document.createDocumentFragment() creates an empty DOM fragment. You can collect nodes in it and then move them into a parent without adding an extra wrapper element.
document.createElement creates a new DOM element with the specified name. It does not automatically insert it into the document.
document.createTextNode(data) creates a Text node containing the supplied content without interpreting it as markup.
Document.documentElement returns the document's root element or null. The property is read-only, but the element itself can be modified.
DOMContentLoaded signals that HTML parsing and deferred script execution have finished. Use it to initialize an interface without waiting for the entire page to load.
DocumentFragment groups DOM nodes without a wrapper element. Inserting the fragment moves its children and leaves it empty.
document.getElementById(elementId) returns the element with the specified ID or null. Matching is case-sensitive and searches the document’s descendants.
Document.hidden is a read-only property indicating whether the browser considers the document hidden. Observe visibilitychange to track changes.
document.querySelector(selectors) finds the first element matching a CSS selector. It returns an element or null; an invalid selector throws an exception.
Finds elements using CSS selectors and returns a static NodeList, including an empty list when nothing matches.
Document.readyState describes the document's loading stage: loading, interactive, or complete. Checking this property helps initialize DOM-related code even when a script loads too late to receive DOMContentLoaded.
Document.title reads and sets a document's title. Reading it normalizes ASCII whitespace.
The visibilitychange event reports a change in document visibility. Read the current state from document.visibilityState.
DataCloneError is the name of a DOMException indicating that data cannot be cloned. Learn a typical cause in structuredClone(), how to recognize the error, and why an unsupported value differs from a supported circular reference.
DOMRect.height is a rectangle's writable vertical dimension. It can be negative and affects the computed top and bottom edges.
`DOMRect.top` is a read-only property that returns the coordinate of a rectangle’s top edge. Even with a negative height, floating-point rounding can make the result equal to `y`.
DOMRect.width is a writable instance property describing a rectangle's width. It holds a floating-point number and permits negative values. Do not confuse it with the read-only DOMRectReadOnly.width property.
DOMStringList is a list of strings exposed by some Web APIs that you do not modify directly. Its contains() method checks whether a supplied string belongs to the list and returns a boolean. A typical use is checking object store names in IndexedDB.
DOMTokenList.add() adds tokens, such as classes through element.classList, skipping duplicates and validating arguments.
DOMTokenList.contains(token) reports whether a list contains the exact token, for example a CSS class in element.classList.
DOMTokenList represents a set of tokens, such as an element's classes exposed through classList. Learn to add, remove, toggle, and check tokens without manually processing the text of the class attribute.
DOMTokenList.remove() removes specified tokens, such as element classes through classList. Learn how multiple arguments, missing tokens, and invalid values are handled.
DOMTokenList.toggle() toggles a token's presence or forces it with force. It returns whether the token is present after the call.