In JavaScript, the document object represents the entire web page loaded in the browser. It is the main entry point to access and manipulate the HTML content, including elements like <head>, <body>, the page title, and URL-related information.
document is part of the Browser Object Model (BOM) and represents the current HTML document.document.body refers to the <body> element (main visible content).document.head refers to the <head> element (meta-data, links, scripts).document.documentElement usually refers to the root <html> element.document.URL and document.lastModified).Commonly used document properties include:
document.title – Get or set the title of the document (browser tab text).document.body – Returns the <body> element.document.head – Returns the <head> element.document.documentElement – Returns the root <html> element.document.URL – Returns the complete URL of the page (read-only).document.domain – Returns the domain name of the server.document.lastModified – Returns the date and time the document was last modified.document.body and child elements.document.URL and document.domain.
console.log(document.title); // Document's title
console.log(document.body); // <body> element
console.log(document.documentElement); // <html> element
console.log(document.URL); // Full URL of the current page
console.log(document.lastModified); // Last modified date/time
// Change the title of the page
document.title = "New Page Title";
console.log(document.head); // <head> element
console.log(document.body); // <body> element
document.title prints the current text shown on the browser tab.document.body prints the whole <body> DOM tree.document.documentElement prints the root <html> element.document.URL prints the full URL of the current page (cannot be changed directly).document.lastModified returns a string with the last modified date and time of the document.document.title immediately updates the browser tab text.Use this mini tool to update the document title dynamically:
document.title. document.body and document.head to quickly access the main sections of the HTML document.document.title to reflect the current state of your app or page (e.g., unread messages count).document.URL or document.domain for URL-based logic or debugging, but remember they are often read-only.document or its properties in the console to explore the DOM structure while learning.<script> at the bottom or use DOMContentLoaded) before accessing elements inside document.body.document.title = "Your Name's Page"; and observe the browser tab.document.body and document.head to the console and inspect their contents in the DevTools.console.log(document.URL) and console.log(document.lastModified).document.documentElement and see how it relates to the entire HTML document.