What is JavaScript HTML DOM Document? Detail with examples and use cases.

The Document Object

When an HTML document is loaded into a web browser, it becomes a document object.

The document object is the root node of the HTML document.

The document object is a property of the window object.

The document object is accessed with:

window.document or just document

The HTML DOM (Document Object Model)

When a web page is loaded, the browser creates a Document Object Model of the page.

With the object model, JavaScript gets all the power it needs to create dynamic HTML.

What is the HTML DOM?

  • The HTML elements as objects
  • The properties of all HTML elements
  • The methods to access all HTML elements
  • The events for all HTML elements

The Objects are organized in a hierarchy. This hierarchical structure applies to the organization of objects in a Web document.

  • Window object − Top of the hierarchy. It is the outmost element of the object hierarchy.
  • Document object − Each HTML document that gets loaded into a window becomes a document object. The document contains the contents of the page.
  • Form object − Everything enclosed in the <form>…</form> tags sets the form object.
  • Form control elements − The form object contains all the elements defined for that object such as text fields, buttons, radio buttons, and checkboxes.

Example

getElementById()

The following example changes the content (the innerHTML) of the <p> element with id="demo" :-

<html>
<body>

<p id=”demo”></p>

<script>
document.getElementById(“demo”).innerHTML = “Hello Roshan!”;
</script>

</body>
</html>

In the example above, getElementById is a method, while innerHTML is a property.

document.write()

<!DOCTYPE html>
<html>
<body>

<script>
document.write(Date());
</script>

</body>
</html>

document.querySelector()

<!DOCTYPE html>
<html>
<body>

<p>Add a background color to the first element with class=”example”: </p>

<script>
document.querySelector(“p”).style.backgroundColor = “red”;
</script>

</body>
</html>

The open() and close() Methods

<!DOCTYPE html>
<html>
<body>

<p>Add a background color to the first element with class=”example”: </p>

<button onclick = “myfunction()”>click me</button>

<script>
function myfuction() {

document.open();
document.write (“<h1> Hello Roshan </h1>”);

document.close();

}
</script>

</body>
</html>

Related Posts

The Complete SEO Playbook for AI Guest Post Generation and Publishing

Introduction Search engine optimization relies heavily on authority, relevance, and trust. While search algorithms continually evolve, securing high-quality backlinks through strategic content placement remains a foundational ranking…

Read More

Top Digital Marketing Workflow Management Tools for Agencies

Introduction Managing a modern digital marketing stack often feels like juggling dozens of disconnected software subscriptions. Marketing managers, agency owners, and SEO specialists frequently find themselves jumping…

Read More

AI Prompt Management Tools: From Basic Prompts to High-Value Digital Assets

Generative artificial intelligence has fundamentally altered how modern enterprises, creative teams, and technical engineers operate. However, as organizations increase their reliance on large language models (LLMs), a…

Read More

Automated Payment Management Software for Modern Enterprises

Finance operations form the backbone of every enterprise, yet many organizations still struggle with fragmented billing tools, delayed collections, and manual reconciliation. Relying on spreadsheets and disconnected…

Read More

The Complete Guide to Choosing the Best Vehicle Rental Management Software

INTRODUCTION Managing a vehicle rental business manually through spreadsheets, paper ledgers, or messaging apps creates significant operational friction. Rental agency owners face recurring challenges including double bookings,…

Read More

The Ultimate Guide to Predictive Alerts and Data Observability

Introduction In modern data-driven enterprises, data pipelines serve as the central circulatory system of business intelligence, operational analytics, machine learning platforms, and executive decision-making. However, as data…

Read More