What is the difference between DOM and HTML?
5 Answers
DOM is a model of a document with an associated API for manipulating it.
HTML is a markup language that lets you represent a certain kind of DOM in text.
Other kinds of DOMs can be expressed in other markup languages, for example RSS and Atom can be converted to a DOM and manipulated with the same API as an HTML or XHTML document (more or less anyway; there are some HTML specific DOM extensions).
-
-
1
-
3For those finding this anno 2020 here you can find the answer to @Amrit and vikramvi their questions: developer.mozilla.org/en-US/docs/Web/API/HTML_DOM_API and here a bit broader but relevant info: developer.mozilla.org/en-US/docs/Web/API/Document_Object_Model/…– Michel KNov 3, 2020 at 15:32
The Document Object Model (DOM) is a language-independent model made up of objects representing the structure of a document. HTML is one language for writing such documents.
Well, if you look in things like firebug, you can also check out the "DOM". Then they usually mean the current state the HTML page is in. So if you, for example, have a html page and add a tag with javascript.
The actual HTML of the page is still the same, but the "DOM" however has changed.
Notice that this isn't the right definition of DOM, but I thought this might be what you meant.
-
DOM: en.wikipedia.org/wiki/Document_object_model HTML: en.wikipedia.org/wiki/HTML– zzzzBovNov 5, 2010 at 21:07
-
1But not only HTML! Also, it doesn't really represent the HTML, but rather it represents the document to which the HTML has been parsed. Nov 5, 2010 at 21:09
-
The HTML of a page is a string, and the DOM of the page is what happens when you take that string and construct an object in the object-oriented programming sense of the term "object". Creating that object is how JavaScript is able to interact with the page:
https://en.wikipedia.org/wiki/Document_Object_Model#JavaScript
When a web page is loaded, the browser creates a Document Object Model of the page, which is an object oriented representation of an HTML document, that acts as an interface between JavaScript and the document itself and allows the creation of dynamic web pages.