HOME

TheInfoList




The Document Object Model (DOM) is a
cross-platform In computing Computing is any goal-oriented activity requiring, benefiting from, or creating computing machinery. It includes the study and experimentation of algorithmic processes and development of both computer hardware , hardware and soft ...

cross-platform
and language-independent interface that treats an
XML Extensible Markup Language (XML) is a markup language #REDIRECT Markup language In computer text processing, a markup language is a system for annotation, annotating a document in a way that is Syntax (logic), syntactically distinguishable fro ...

XML
or
HTML The HyperText Markup Language, or HTML is the standard markup language #REDIRECT Markup language In computer text processing, a markup language is a system for annotation, annotating a document in a way that is Syntax (logic), syntacticall ...

HTML
document as a
tree structure A tree structure, tree diagram, or tree model is a way of representing the hierarchical A hierarchy (from Ancient Greek, Greek: , from , 'president of sacred rites') is an arrangement of items (objects, names, values, categories, etc.) that a ...

tree structure
wherein each
node In general, a node is a localized swelling (a "knot A knot is an intentional complication in Rope, cordage which may be practical or decorative, or both. Practical knots are classified by function, including hitches, bends, loop knots, and splic ...
is an
object Object may refer to: General meanings * Object (philosophy), a thing, being, or concept ** Entity, something that is tangible and within the grasp of the senses ** Object (abstract), an object which does not exist at any particular time or pl ...
representing a part of the document. The DOM represents a document with a logical tree. Each branch of the tree ends in a node, and each node contains objects. DOM methods allow programmatic access to the tree; with them one can change the structure, style or content of a document. Nodes can have
event handler In programming and software design Software design is the process by which an Agency (philosophy), agent creates a specification of a Artifact (software development), software artifact intended to accomplish goals, using a set of primitive comp ...
s attached to them. Once an event is triggered, the event handlers get executed. The principal standardization of the DOM was handled by the
World Wide Web Consortium The World Wide Web Consortium (W3C) is the main international standards organization A standards organization, standards body, standards developing organization (SDO), or standards setting organization (SSO) is an organization whose primary ...
(W3C), which last developed a recommendation in 2004.
WHATWG The Web Hypertext Application Technology Working Group (WHATWG) is a community of people interested in evolving HTML and related technologies. The WHATWG was founded by individuals from Apple Inc., the Mozilla Foundation and Opera Software, lea ...
took over the development of the standard, publishing it as a
living document A living document, also known as an evergreen document or dynamic document, is a document A document is a writing, written, drawing, drawn, presented, or memorialized representation of thought, often the manifestation of nonfiction, non-fiction ...
. The W3C now publishes stable snapshots of the WHATWG standard.


History

The history of the Document Object Model is intertwined with the history of the "
browser wars A browser war is competition for dominance in the usage share of web browsers The usage share of web browsers is the proportion, often expressed as a percentage, of visitors to a group of that use a particular . Accuracy Measuring bro ...
" of the late 1990s between
Netscape Navigator Netscape Navigator was a proprietary web browser A web browser (commonly referred to as a browser) is application software for accessing the World Wide Web upright=1.35, A global map of the web index for countries in 2014 The World ...
and
Microsoft Internet Explorer Internet Explorer (formerly Microsoft Internet Explorer and Windows Internet Explorer, commonly abbreviated IE or MSIE) is a series of graphical user interface, graphical web browsers developed by Microsoft and included in the Microsoft Windows ...
, as well as with that of
JavaScript JavaScript (), often abbreviated JS, is a programming language A programming language is a formal language In mathematics Mathematics (from Ancient Greek, Greek: ) includes the study of such topics as quantity (number theory), ma ...

JavaScript
and
JScript JScript is Microsoft's dialect of the ECMAScript standard that is used in Microsoft's Internet Explorer. JScript is implemented as an Active Scripting engine. This means that it can be "plugged in" to OLE Automation applications that support Ac ...
, the first
scripting language A scripting language or script language is a programming language A programming language is a formal language In mathematics Mathematics (from Ancient Greek, Greek: ) includes the study of such topics as quantity (number theory), mathe ...
s to be widely implemented in the
JavaScript engines A JavaScript engine is a computer program A computer program is a collection of instructions that can be executed by a computer to perform a specific task. A computer program is usually written by a computer programmer in a programming lang ...
of
web browser A web browser (commonly referred to as a browser) is application software for accessing the World Wide Web. When a User (computing), user requests a web page from a particular website, the web browser retrieves the necessary content from a web ...

web browser
s. JavaScript was released by
Netscape Communications Netscape Communications Corporation (originally Mosaic Communications Corporation) was an American independent computer services company with headquarters in Mountain View, California Mountain View is a city in Santa Clara County, California ...
in 1995 within Netscape Navigator 2.0. Netscape's competitor,
Microsoft Microsoft Corporation is an American multinational corporation, multinational technology company, technology corporation which produces Software, computer software, consumer electronics, personal computers, and related services. Its best-know ...

Microsoft
, released Internet Explorer 3.0 the following year with a reimplementation of JavaScript called JScript. JavaScript and JScript let
web developer Web Developer is an Mozilla extension, extension for Mozilla-based web browsers that adds editing and debugging tools for web developers. It has been tested to be compatible with Firefox, Flock (web browser), Flock, and SeaMonkey, Seamonkey. The e ...
s create web pages with
client-side Client-side refers to operations that are performed by the client in a client–server relationship in a computer network A computer network is a set of s sharing resources located on or provided by . The computers use common s over to ...
interactivity. The limited facilities for detecting user-generated
events Event may refer to: Gatherings of people * Ceremony, an event of ritual significance, performed on a special occasion * Convention (meeting), a gathering of individuals engaged in some common interest * Event management, the organization of event ...
and modifying the HTML document in the first generation of these languages eventually became known as "DOM Level 0" or "Legacy DOM." No independent standard was developed for DOM Level 0, but it was partly described in the specifications for
HTML 4 The HyperText Markup Language, or HTML is the standard markup language #REDIRECT Markup language In computer text processing, a markup language is a system for annotation, annotating a document in a way that is Syntax (logic), syntacticall ...
. Legacy DOM was limited in the kinds of
element Element may refer to: Science * Chemical element Image:Simple Periodic Table Chart-blocks.svg, 400px, Periodic table, The periodic table of the chemical elements In chemistry, an element is a pure substance consisting only of atoms that all ...
s that could be accessed.
Form Form is the shape A shape or figure is the form of an object or its external boundary, outline, or external Surface (mathematics), surface, as opposed to other properties such as color, Surface texture, texture, or material type. A plane shap ...
,
link #REDIRECT Link Link or Links may refer to: Places * Link, West Virginia, an unincorporated community in the US * Link River, Klamath Falls, Oregon, US People with the name * Link (singer) (Lincoln Browder, born 1964), American R&B singer * L ...

link
and image elements could be referenced with a hierarchical name that began with the root document object. A hierarchical name could make use of either the names or the sequential index of the traversed elements. For example, a
form input element
form input element
could be accessed as either document.formName.inputName or document.forms elements /code>. The Legacy DOM enabled client-side form validation and simple interface interactivity like creating . In 1997, Netscape and Microsoft released version 4.0 of Netscape Navigator and Internet Explorer respectively, adding support for
Dynamic HTML Dynamic HTML, or DHTML, is a collection of technologies used together to create interactive and animated website A website (also written as web site) is a collection of web page A web page (or webpage) is a hypertext Hyperte ...
(DHTML) functionality enabling changes to a loaded HTML document. DHTML required extensions to the rudimentary document object that was available in the Legacy DOM implementations. Although the Legacy DOM implementations were largely compatible since JScript was based on JavaScript, the DHTML DOM extensions were developed in parallel by each browser maker and remained incompatible. These versions of the DOM became known as the "Intermediate DOM." After the standardization of
ECMAScript ECMAScript () (or ES) is a JavaScript JavaScript (), often abbreviated JS, is a programming language A programming language is a formal language In mathematics Mathematics (from Ancient Greek, Greek: ) includes the study of s ...
, the
W3C The World Wide Web Consortium (W3C) is the main international standards organization A standards organization, standards body, standards developing organization (SDO), or standards setting organization (SSO) is an organization whose primary ...
DOM Working Group began drafting a standard DOM specification. The completed specification, known as "DOM Level 1", became a W3C Recommendation in late 1998. By 2005, large parts of W3C DOM were well-supported by common ECMAScript-enabled browsers, including Microsoft Internet Explorer version 6 (from 2001),
Opera Opera is a form of theatre Theatre or theater is a collaborative form of performing art that uses live performers, usually actor, actors or actresses, to present the experience of a real or imagined event before a live audience in a s ...
,
Safari A safari (; ) is an overland journey to or (in more recent times) observe , especially in or . The so-called animals of Africa – , , , , and – particularly form an important part of the safari market, both for and . Etymology The ...
and
Gecko Geckos are small, mostly carnivorous lizards that have a wide distribution, found on every continent except Antarctica. Belonging to the infraorder#Hierarchy of ranks, infraorder Gekkota, geckos are found in warm climates throughout the world. T ...
-based browsers (like
Mozilla Mozilla (stylized as moz://a) is a free software Free software (or libre software) is computer software distributed under terms that allow users to run the software for any purpose as well as to study, change, and distribute it and any a ...
,
Firefox Mozilla Firefox or simply Firefox is a free and open-source Free and open-source software (FOSS) is software that is both free software and open-source software where anyone is free software license, freely licensed to use, copy, study, ...

Firefox
,
SeaMonkey SeaMonkey is a free and open-source Internet suite. It is the continuation of the former Mozilla Application Suite, based on the same source code, which itself grew out of Netscape Communicator and formed the base of Netscape 6 and Netscape 7. ...

SeaMonkey
and Camino).


Standards

The
W3C The World Wide Web Consortium (W3C) is the main international standards organization A standards organization, standards body, standards developing organization (SDO), or standards setting organization (SSO) is an organization whose primary ...

W3C
DOM Working Group published its final recommendation and subsequently disbanded in 2004. Development efforts migrated to the
WHATWG The Web Hypertext Application Technology Working Group (WHATWG) is a community of people interested in evolving HTML and related technologies. The WHATWG was founded by individuals from Apple Inc., the Mozilla Foundation and Opera Software, lea ...
, which continues to maintain a living standard. In 2009, the Web Applications group reorganized DOM activities at the W3C. In 2013, due to a lack of progress and the impending release of
HTML5 HTML5 is a markup language #REDIRECT Markup language In computer text processing, a markup language is a system for annotation, annotating a document in a way that is Syntax (logic), syntactically distinguishable from the text, meaning when ...

HTML5
, the DOM Level 4 specification was reassigned to the
HTML Working Group The HTML Working Group was an Internet Engineering Task Force (IETF) working group from 1994 to 1996, and a World Wide Web Consortium (W3C) working group from 1997 to 2015. The working group was co-chaired by Paul Cotton (software developer), ...
to expedite its completion. Meanwhile, in 2015, the Web Applications group was disbanded and DOM stewardship passed to the Web Platform group. Beginning with the publication of DOM Level 4 in 2015, the W3C creates new recommendations based on snapshots of the WHATWG standard. * DOM Level 1 provided a complete model for an entire HTML or
XML Extensible Markup Language (XML) is a markup language #REDIRECT Markup language In computer text processing, a markup language is a system for annotation, annotating a document in a way that is Syntax (logic), syntactically distinguishable fro ...

XML
document, including the means to change any portion of the document. * DOM Level 2 was published in late 2000. It introduced the getElementById function as well as an
event model In Computer programming, programming and software design, an event is an action or occurrence recognized by software, often originating asynchronous I/O, asynchronously from the external environment, that may be Event handler, handled by the softwa ...
and support for
XML namespace#REDIRECT XML namespace XML namespaces are used for providing uniquely named Data element, elements and attributes in an XML document. They are defined in a W3C recommendation. An XML instance may contain element or attribute names from more than one ...
s and CSS. * DOM Level 3, published in April 2004, added support for
XPath XPath (XML Path Language) is a query language for selecting Node (computer science), nodes from an XML document. In addition, XPath may be used to compute values (e.g., String (computer science), strings, numbers, or Boolean datatype, Boolean val ...
and keyboard
event handling Event may refer to: Gatherings of people * Ceremony, an event of ritual significance, performed on a special occasion * Convention (meeting), a gathering of individuals engaged in some common interest * Event management, the organization of event ...
, as well as an interface for documents as XML. * DOM Level 4 was published in 2015. It is a snapshot of the WHATWG living standard.


Applications


Web browsers

To render a document such as a HTML page, most web browsers use an internal model similar to the DOM. The nodes of every document are organized in a
tree structure A tree structure, tree diagram, or tree model is a way of representing the hierarchical A hierarchy (from Ancient Greek, Greek: , from , 'president of sacred rites') is an arrangement of items (objects, names, values, categories, etc.) that a ...

tree structure
, called the ''DOM tree'', with the topmost node named as "Document object". When an HTML page is rendered in browsers, the browser downloads the HTML into local memory and automatically parses it to display the page on screen. However, the DOM does not necessarily need to be represented as a tree, and some browsers have used other internal models.


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. This allows the creation of
dynamic web page A server-side dynamic web page is a web page A web page (or webpage) is a hypertext Hypertext is text displayed on a or other with references () to other text that the reader can immediately access. Hypertext documents are inter ...
s, because within a page JavaScript can: * add, change, and remove any of the HTML elements and attributes * change any of the CSS styles * react to all the existing events * create new events


Implementations

Because the DOM supports navigation in any direction (e.g., parent and previous sibling) and allows for arbitrary modifications, an implementation must at least buffer the document that has been read so far (or some parsed form of it).


Layout engines

Web browsers rely on layout engines to parse HTML into a DOM. Some layout engines, such as Trident/MSHTML, are associated primarily or exclusively with a particular browser, such as Internet Explorer. Others, including
Blink Blinking is a bodily function; it is a semi-autonomic rapid closing of the eyelid An eyelid is a thin fold of skin that covers and protects an eye Eyes are organs of the visual system The visual system comprises the sensory organ ...
,
WebKit #REDIRECT WebKit#REDIRECT WebKit WebKit is a browser engine developed by Apple Inc., Apple and primarily used in its Safari (web browser), Safari web browser, as well as all iOS web browsers. WebKit is also used by the BlackBerry Browser, PlaySta ...
, and
Gecko Geckos are small, mostly carnivorous lizards that have a wide distribution, found on every continent except Antarctica. Belonging to the infraorder#Hierarchy of ranks, infraorder Gekkota, geckos are found in warm climates throughout the world. T ...
, are shared by a number of browsers, such as
Google Chrome Google Chrome is a cross-platform web browser developed by Google. It was first released in 2008 for Microsoft Windows, built with free software components from Apple WebKit and Mozilla Firefox. It was later ported to Linux, macOS, iOS, and An ...

Google Chrome
,
Opera Opera is a form of theatre Theatre or theater is a collaborative form of performing art that uses live performers, usually actor, actors or actresses, to present the experience of a real or imagined event before a live audience in a s ...
,
Safari A safari (; ) is an overland journey to or (in more recent times) observe , especially in or . The so-called animals of Africa – , , , , and – particularly form an important part of the safari market, both for and . Etymology The ...
, and
Firefox Mozilla Firefox or simply Firefox is a free and open-source Free and open-source software (FOSS) is software that is both free software and open-source software where anyone is free software license, freely licensed to use, copy, study, ...

Firefox
. The different layout engines implement the DOM standards to varying degrees of compliance.


Libraries

DOM implementations: *
libxml2 libxml2 is a software library Image:Ogg vorbis libs and application dia.svg, 277px, Illustration of an application which uses libvorbisfile to play an Ogg Vorbis file In computer science, a library is a collection of non-volatile memory, non-v ...
*
MSXML Microsoft XML Core Services (MSXML) are set of services that allow applications written in JScript JScript is Microsoft's dialect of the ECMAScript standard that is used in Microsoft's Internet Explorer. JScript is implemented as an Active Scr ...
* Xerces is a collection of DOM implementations written in C++, Java and Perl
xml.dom
for
Python Python may refer to: * Pythonidae The Pythonidae, commonly known as pythons, are a family of nonvenomous snakes found in Africa, Asia, and Australia. Among its members are some of the largest snakes in the world. Ten genera and 42 species ...
* XML for <SCRIPT> is a JavaScript-based DOM implementation
PHP.Gt DOM
is a server-side DOM implementation based on
libxml2 libxml2 is a software library Image:Ogg vorbis libs and application dia.svg, 277px, Illustration of an application which uses libvorbisfile to play an Ogg Vorbis file In computer science, a library is a collection of non-volatile memory, non-v ...
and brings DOM level 4 compatibility to the
PHP PHP is a general-purpose scripting language A scripting language or script language is a programming language A programming language is a formal language comprising a Instruction set architecture, set of instructions that produce various k ...

PHP
programming language
Domino
is a Server-side (Node.js) DOM implementation based on Mozilla's dom.js. Domino is used in the
MediaWiki MediaWiki is a free and open-source Free and open-source software (FOSS) is software that is both free software and open-source software where anyone is free software license, freely licensed to use, copy, study, and change the softwa ...

MediaWiki
stack with Visual Editor.
SimpleHtmlDom
is a simple HTML document object model in C#, which can generate HTML string programmatically. APIs that expose DOM implementations: * JAXP (Java API for XML Processing) is an API for accessing DOM providers * Lazarus (
Free Pascal Free Pascal Compiler (FPC) is a compiler for the closely related programming-language dialects Pascal (programming language), Pascal and Object Pascal. It is free software released under the GNU General Public License, witexception clausesthat al ...
IDE) contains two variants of the DOM - with UTF-8 and ANSI format Inspection tools: * is a web developer tool


See also

* Shadow DOM * Virtual DOM


References


General references

* * * *


External links


DOM Living Standard
by the WHATWG
Original W3C DOM hub
by the W3C DOM Working Group (outdated)
Web Platform Working Group
(current steward of W3C DOM) {{DEFAULTSORT:Document Object Model Application programming interfaces HTML Object models
World Wide Web Consortium standards This is a collection of web standards formalized by the World Wide Web Consortium. International standards Standards by organization Web standards World Wide Web Consortium {{CatAutoTOC ...
XML-based standards This category exists to combine the sometimes bewildering array of abbreviations associated with XML technology, not all of which are endorsed by the same organisations. XML Computer standards Communications protocols {{CatAutoTOC ...