JavaScript DOM Document

Subject: JavaScript

The document object is part of the window object (window.document) and is automatically created by the browser when a page loads. It allows developers to select, create, modify, and delete HTML elements dynamically.


Common document Properties and Methods

Example 1: Accessing Document Properties


Example 2: Creating and Writing Content Using document.write()

Note: document.write() should only be used for testing. It can overwrite the entire document if used after the page has loaded.


Example 3: Creating an Element Dynamically


Key Takeaways

  • The document object is the root of the DOM tree.
  • Use document to access and modify elements, metadata, and page structure.
  • Methods like getElementById, querySelector, and createElement operate via document.
  • Avoid using document.write() in production as it is outdated and can cause issues.
  • The document object is essential for creating dynamic and interactive web pages.
Next : DOM Elements