#1 India's Top IT Training Institute
×

About Uncodemy

Know more about who we are and what we stand for.

About Us

About Us

Discover our mission to equip individuals with essential IT skills and industry expertise.

Read More →
UnCodeMy Gallery

UnCodeMy Gallery

Explore highlights from our IT training sessions and success stories.

Read More →
Mentors

Mentors

Meet the industry experts who train and guide you through your course.

Read More →
Free Resources

Free Resources

Free tutorials, interview questions, tools and calculators to help you learn.

Explore →
×

Free Resources

Learn, practice and plan your career — bilkul free.

Tutorials

Tutorials

Step-by-step written tutorials to learn any technology at your own pace.

Read More →
Free Counselling

Free Counselling

Book a free video counselling session and pick the right course for you.

Read More →
Online Compiler

Online Compiler

Write, run and test your code online — no setup required.

Read More →
JavaScript Fundamentals

Types of DOM

"Types of DOM" usually refers to how the Document Object Model standard was divided into parts for different kinds of documents: the Core DOM, the XML DOM and the HTML DOM. The term is also used for the different types of nodes inside the tree, and people often meet related ideas like the Shadow DOM and the virtual DOM. Sorting these terms out early makes later DOM lessons much easier to follow.

Core DOM, XML DOM and HTML DOM

The original W3C specifications split the DOM into layers:

PartWhat it coversExamples of what it provides
Core DOMThe shared model for any structured documentNodes, parents and children, appendChild, getAttribute
XML DOMCore DOM applied to XML documentsReading an RSS feed or an XML response with DOMParser
HTML DOMExtra objects and properties for HTML pagesdocument.body, document.forms, input.value, img.src

The Core DOM knows only about generic elements and attributes. The HTML DOM adds convenient, HTML-specific features on top. For example, every element can use the core method getAttribute('href'), but an <a> element in the HTML DOM also offers an href property that gives you the full resolved URL.

Today, browsers follow the DOM and HTML Living Standards maintained by WHATWG, which merge these ideas. The three-way split is still a useful way to understand where a feature comes from.

Types of nodes in the tree

Whatever kind of document it is, the DOM is made of nodes, and each node has a type, available through its nodeType property:

  • Document node (nodeType 9): the root, which is the document object itself.
  • Element node (1): each tag, such as <p> or <div>.
  • Text node (3): the text inside elements, including whitespace between tags.
  • Comment node (8): HTML comments.
  • Attribute nodes exist in the specification but are not children in the tree; you work with attributes through element methods.
<ul id="menu">
  <li>Home</li>
  <!-- more items later -->
</ul>

<script>
  const menu = document.getElementById('menu');

  menu.childNodes.forEach((node) => {
    console.log(node.nodeType, node.nodeName);
  });
  // 3 "#text"     (whitespace)
  // 1 "LI"
  // 3 "#text"
  // 8 "#comment"
  // 3 "#text"

  console.log(menu.children.length);   // 1, elements only
</script>

The whitespace text node trap

That output explains a classic beginner bug. Properties like childNodes, firstChild and nextSibling include every node, so the line breaks between your tags appear as text nodes. Code that expects menu.firstChild to be the first <li> gets a whitespace text node instead. Use the element-only versions: children, firstElementChild and nextElementSibling.

Shadow DOM and virtual DOM

Two more terms often appear alongside "types of DOM", though they are not parts of the original split:

  • Shadow DOM is a real browser feature. It lets a component attach a hidden, separate DOM tree to an element, so its styles and markup do not leak out or get affected by the page. Built-in controls like <video> use it, and web components can too.
  • Virtual DOM is not a browser feature at all. It is a technique used by libraries such as React: a lightweight JavaScript copy of the UI that is compared with the previous copy, so only the necessary real DOM changes are made.

What to remember

The Core DOM gives the shared tree model, the HTML DOM adds page-specific conveniences, and the XML DOM applies the same model to XML. Inside any of them, elements, text and comments are different node types, and choosing element-only properties saves you from whitespace surprises.

Ready to master real-world web development?

Learn HTML, CSS3, Bootstrap and JavaScript hands-on with mentor-led sessions.

Explore Course