Year End Sale: Get Upto 40% OFF on Live Training! Offer Ending in
D
H
M
S
Get Now
Understanding DOM and BOM

Understanding DOM and BOM

01 Feb 2024
Intermediate
36.1K Views
5 min read
Learn with an interactive course and practical hands-on labs

Free Javascript Course: Learn Javascript In 21 Days

DOM stands for Document Object Model. It is a standard defined by W3C (World Wide Web Consortium). DOM is a programming interface (API) for representing and interacting with HTML, XHTML and XML documents. It organizes the elements of the document in a tree structure (DOM tree) and in the DOM tree, all elements of the document are defined as objects (tree nodes) which have properties and methods.

In simple terms, the DOM is a way to represent the webpage in a structured hierarchical manner so that it will become easier for programmers and end-users to glide through the whole document. With the DOM, we can easily access and manipulate various tags available in DOM, attributes, IDs, classes, or the whole piece elements using commands or methods provided by Document objects and one of the most popular is "getElementById()" to access the specific element by using the ID attribute.

DOM tree objects can be accessed and manipulated with the help of any programming language since it is cross-platform and language-independent. Typically, we manipulate the DOM tree with the help of JavaScript and jQuery using multiple ways of accessing elements by their class names, ID, or the name of the element.

DOM API

Here, I am sharing some DOM API's objects, methods and properties.

DOM API Objects

  1. window

    The window object represents an open window containing a DOM document.

  2. document

    The document object represents the HTML document in a specific window.

  3. history

    This object contains information about the URLs visited by the client.

  4. location

    This object contains information about the current URL.

  5. navigator

    This object contains information about the client.

Read More: Javascript Developer Salary in India

DOM API Methods

DOM methods are actions that you can perform on document elements.

  1. appendChild

    This method appends an element as a child to the object.

  2. createElement

    This method creates an instance of the element for the specified tag.

  3. reload

    This method reloads the current document.

  4. removeNode

    This method removes the object from the document hierarchy.

Read More: 50+ Javascript Interview Questions and Answers

DOM API Properties

HTML DOM properties are values (of document Elements) that you can set or change

  1. appName

    This property retrieves the name of the client.

  2. appVersion

    This property Retrieves the platform and version of the application.

  3. href

    This property sets or retrieves the entire URL as a string.

DOM API Example

DOM API Example

HTML DOM

When a web page is loaded, the browser creates a DOM tree for all the objects (Html elements) of that page. The HTML DOM is full object-oriented representation of your web page and in HTML DOM each and everything is a node. DOM tree nodes can be removed, added, and replaced by using DOM API.

Types of HTML DOM Tree Nodes

  1. Document Node

    This node represents the HTML document.

  2. Element Node

    This node represents an HTML element.

  3. Attribute Node

    This node represents an HTML element's attribute.

  4. Text Node

    This node represents Text inside an HTML element.

  5. Comment Node

    This node represents HTML Comment.

A Simple DOM Tree

<HTML>
<HEAD>
 <TITLE>Your Title</TITLE>
 <SCRIPT src="www.webgeekschool.com/jsfile.js"></SCRIPT>
</HEAD>
<BODY>
 <DIV>Your Div Text</DIV>
 <P>Your Para Text</p>
</BODY>
</HTML>

DOM tree representation of the above web page is given below:

BOM

BOM stands for Browser Object Model. Unlike DOM, there is no standard defined for BOM, hence different browsers implement it in different ways. Typically, the collection of browser objects is collectively known as the Browser Object Model.

BOM's main task is to manage browser windows and enable communication between the windows. Each HTML page that is loaded into a browser window becomes a Document object and document object is an object in the BOM. You can say BOM is a superset of DOM. BOM has many objects, methods, and properties that are not the part of the DOM structure.

The important BOM objects are as:

  1. document

  2. location

  3. history

  4. navigator

  5. screen

  6. frames

BOM Objects Example

Browser object model

What do you think?

I hope, now you have a better understanding of DOM and BOM. I would like to have feedback from my blog readers. Your valuable feedback, question, or comments about this article are always welcome.

Take our Javascript skill challenge to evaluate yourself!

In less than 5 minutes, with our skill challenge, you can identify your knowledge gaps and strengths in a given skill.

GET FREE CHALLENGE

Share Article
About Author
Shailendra Chauhan (Microsoft MVP, Founder & CEO at ScholarHat)

Shailendra Chauhan, Founder and CEO of ScholarHat by DotNetTricks, is a renowned expert in System Design, Software Architecture, Azure Cloud, .NET, Angular, React, Node.js, Microservices, DevOps, and Cross-Platform Mobile App Development. His skill set extends into emerging fields like Data Science, Python, Azure AI/ML, and Generative AI, making him a well-rounded expert who bridges traditional development frameworks with cutting-edge advancements. Recognized as a Microsoft Most Valuable Professional (MVP) for an impressive 9 consecutive years (2016–2024), he has consistently demonstrated excellence in delivering impactful solutions and inspiring learners.

Shailendra’s unique, hands-on training programs and bestselling books have empowered thousands of professionals to excel in their careers and crack tough interviews. A visionary leader, he continues to revolutionize technology education with his innovative approach.
Accept cookies & close this