Basic Properties & Methods
document.title
→ Get or set the page title.
document.body
→ Access the <body>
element.
document.documentElement
→ Access the <html>
element.
document.head
→ Access the <head>
element.
document.referrer
→ Get the referrer URL.
document.readyState
→ Get the document loading state (loading
/ interactive
/ complete
).
document.hasFocus()
→ Check if the document is active.
document.visibilityState
→ Check if the page is visible (visible
/ hidden
).
document.domain
→ Get or set the current domain (for cross-subdomain communication).
document.activeElement
→ Returns the currently focused element.
console.log(document.title);
document.title = "New Page Title";
console.log(document.activeElement); // Logs the element currently in focus
Selecting & Modifying Elements
document.getElementById(id)
→ Select an element by ID.
document.querySelector(selector)
→ Select the first matching element.
document.createElement(tagName)
→ Create a new element.
document.createTextNode(text)
→ Create a text node.
document.appendChild(node)
→ Append an element.
const div = document.createElement("div");
div.textContent = "Hello, Document!";
document.body.appendChild(div);
Advanced Document APIs