Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Document tree is the same as DOM?

Tags:

html

dom

css

Here is the sentence

The pseudo-class concept is introduced to permit selection based on information that lies outside of the document tree or that cannot be expressed using the other simple selectors.

from http://www.w3.org/TR/selectors/#pseudo-classes

Is "document tree" have the same meaning as DOM or it's something else?

like image 512
Artem Svirskyi Avatar asked Jun 28 '14 10:06

Artem Svirskyi


2 Answers

Yes.

DOM stands for document object model and describes the tree strcuture of elements that form the (HTML) document.

When the CSS spec talks about a document tree it refers to the same thing.

In the sentence you've cited the document says the information, for example whether a link has been visited or not, is not stored in a DOM node.

Take a look at this screenshot of the Firebug inspector showing a part of the DOM of this question and the DOM properties.

Firebug: Document tree excerpt of this question showing the link to the W3C docs and the DOM properties pane

In CSS you could create this selector and apply styles to a link that has been visited:

a:visited {
    ...
}

There's no visited attribute in the DOM node that Javascript could access too, thus this informaion is outside the DOM tree.

like image 91
try-catch-finally Avatar answered Nov 04 '22 22:11

try-catch-finally


For the purposes of using CSS with HTML, whether you call it a document tree or a DOM tree doesn't make much of a difference. As an author working with HTML and CSS, all you need to know is that the tree is the structure of elements as marked up in the HTML.

The DOM, short for Document Object Model, is a set of APIs through which elements of an HTML or XML document can be accessed and modified. Strictly speaking, the DOM, in itself, is not the document tree (or a document tree for that matter), but an interface to said tree (although the tree itself can be implemented according to the DOM). See What is the Document Object Model? in the DOM spec for a lengthy explanation.

Furthermore, a document tree may not necessarily be represented or interfaced with by the DOM, since CSS may be used to style things other than HTML or XML DOM trees. The DOM provides just one implementation of the concept of a "document tree". This is why the Selectors spec (and related specs) never refer to the document tree as "the DOM" or "the DOM tree", except when specifically referring to the DOM standard.

The definition of a "document tree" according to CSS, then, can be found in the CSS2.1 spec:

Document tree
The tree of elements encoded in the source document. Each element in this tree has exactly one parent, with the exception of the root element, which has none.

When the source document language is HTML or XML, and the implementation used is the DOM, the resulting document tree is a DOM tree.

like image 43
BoltClock Avatar answered Nov 04 '22 23:11

BoltClock