DOM

DOM

Source
  1. If namespace is the empty string, set it to null.
  2. If both namespace and localName are "*" (U+002A), return a HTMLCollection rooted at root, whose filter matches descendant elements.
  3. Otherwise, if namespace is "*" (U+002A), return a HTMLCollection rooted at root, whose filter matches descendant elements whose local name is localName.
  4. Otherwise, if localName is "*" (U+002A), return a HTMLCollection rooted at root, whose filter matches descendant elements whose namespace is namespace.
  5. Otherwise, return a HTMLCollection rooted at root, whose filter matches descendant elements whose namespace is namespace and local name is localName.

When invoked with the same arguments, the same HTMLCollection object may be returned as returned by an earlier call.

The list of elements with class names classNames for a node root is the HTMLCollection returned by the following algorithm:

When invoked with the same argument, the same HTMLCollection object may be returned as returned by an earlier call.

Document

In all current engines.

Firefox1+Safari1+Chrome1+ Opera3+Edge79+ Edge (Legacy)12+IE4+ Firefox for Android4+iOS Safari1+Chrome for Android18+Android WebView1+Samsung Internet1.0+Opera Mobile10.1+

XMLDocument

In all current engines.

Firefox1+Safari10+Chrome34+ Opera21+Edge79+ Edge (Legacy)18IENone Firefox for Android4+iOS Safari10+Chrome for Android34+Android WebView37+Samsung Internet2.0+Opera Mobile21+


[Exposed=Window]
interface Document : ); , ); ); [, optional ( = {}); [, , optional ( = {}); [); [); [, ); [, optional  = false); [); [); [, ); [); // legacy [, optional  = 0xFFFFFFFF, optional  = null); [, optional  = 0xFFFFFFFF, optional  = null);
}; [Exposed=Window]
interface XMLDocument : Document {}; dictionary ElementCreationOptions { DOMString is;
};

Document nodes are simply
known as documents.

Each document has an associated encoding (an encoding), content type (a string), URL (a URL), origin (an origin), type ("xml" or "html"), and mode ("no-quirks", "quirks", or "limited-quirks"). [ENCODING] [URL] [HTML]

Unless stated otherwise, a document’s encoding is the utf-8 encoding, content type is
"application/xml", if its mode is "quirks", and limited-quirks mode if its mode is "limited-quirks".

The mode is only ever changed from the default for documents created by the HTML parser based on the presence, absence, or value of the DOCTYPE string, and by a new browsing context (initial "about:blank"). [HTML]

No-quirks mode was originally known as "standards mode" and limited-quirks mode was once known as "almost standards mode". They have been renamed because their details are now defined by standards. (And because Ian Hickson vetoed their original names on the basis that they are nonsensical.)

A document’s get the parent algorithm, given an event, returns
null if event’s type attribute value is "load" or document does not have a browsing context; otherwise the document’s relevant global object.

document = new Document() Returns a new document. document . implementation Returns document’s DOMImplementation object. document . URL document . documentURI Returns document’s URL. document . compatMode Returns the string "BackCompat" if document’s mode is "quirks"; otherwise "CSS1Compat". document . characterSet Returns document’s encoding. document . contentType Returns document’s content type.

Document/Document

In all current engines.

Firefox20+Safari6.1+Chrome60+ Opera47+Edge79+ Edge (Legacy)17+IENone Firefox for Android20+iOS Safari6.1+Chrome for Android60+Android WebView60+Samsung Internet8.0+Opera Mobile44+

The new Document() constructor
steps are to set this’s origin to the origin of current global object’s associated Document. [HTML]

Unlike createDocument(), this constructor does not
return an XMLDocument object, but a document (Document object).

Document/implementation

In all current engines.

Firefox1+Safari1+Chrome1+ Opera12.1+Edge79+ Edge (Legacy)12+IE6+ Firefox for Android4+iOS Safari1+Chrome for Android18+Android WebView1+Samsung Internet1.0+Opera Mobile12.1+

The implementation getter steps are to return the DOMImplementation object that is associated with this.

Document/URL

In all current engines.

Firefox1+Safari1+Chrome1+ Opera3+Edge79+ Edge (Legacy)12+IE4+ Firefox for Android4+iOS Safari1+Chrome for Android18+Android WebView1+Samsung Internet1.0+Opera Mobile10.1+

Document/documentURI

In all current engines.

Firefox1+Safari3+Chrome1+ Opera12.1+Edge79+ Edge (Legacy)17+IENone Firefox for Android4+iOS Safari1+Chrome for Android18+Android WebView1+Samsung Internet1.0+Opera Mobile12.1+

The URL and documentURI getter steps are to return this’s URL, serialized.

Document/compatMode

In all current engines.

Firefox1+Safari3.1+Chrome1+ Opera12.1+Edge79+ Edge (Legacy)12+IE6+ Firefox for Android4+iOS Safari2+Chrome for Android18+Android WebView1+Samsung Internet1.0+Opera Mobile12.1+

The compatMode getter steps are to return
"BackCompat" if this’s mode is "quirks";
otherwise "CSS1Compat".

Document/characterSet

In all current engines.

Firefox1+Safari3+Chrome1+ Opera12.1+Edge79+ Edge (Legacy)12+IE9+ Firefox for Android4+iOS Safari1+Chrome for Android18+Android WebView1+Samsung Internet1.0+Opera MobileYes

The characterSet, charset, and inputEncoding getter steps are to return this’s encoding’s name.

Document/contentType

In all current engines.

Firefox1+Safari9+Chrome36+ Opera23+Edge79+ Edge (Legacy)17+IENone Firefox for Android4+iOS Safari9+Chrome for Android36+Android WebView37+Samsung Internet3.0+Opera Mobile24+

The contentType getter steps are to return this’s content type.

document . doctype Returns the doctype or null if there is none. document . documentElement Returns the document element. collection = document . getElementsByTagName(qualifiedName)

If qualifiedName is "*" returns a HTMLCollection of all descendant elements.

Otherwise, returns a HTMLCollection of all descendant elements whose qualified name is qualifiedName. (Matches case-insensitively against elements in the HTML namespace within an HTML document.)

collection = document . getElementsByTagNameNS(namespace, localName) If namespace and localName are "*" returns a HTMLCollection of all descendant elements.

If only namespace is "*" returns a HTMLCollection of all descendant elements whose local name is localName.

If only localName is "*" returns a HTMLCollection of all descendant elements whose namespace is namespace.

Otherwise, returns a HTMLCollection of all descendant elements whose namespace is namespace and local name is localName.

collection = document . getElementsByClassName(classNames) collection = element . getElementsByClassName(classNames) Returns a HTMLCollection of the elements in the object on which the method was invoked (a document or an element) that have all the classes given by classNames. The classNames argument is interpreted as a space-separated list of classes.

Document/doctype

In all current engines.

Firefox1+Safari1+Chrome1+ Opera12.1+Edge79+ Edge (Legacy)12+IE6+ Firefox for Android4+iOS Safari1+Chrome for Android18+Android WebView1+Samsung Internet1.0+Opera Mobile12.1+

The doctype getter steps are to return the child of this that is a doctype; otherwise null.

Document/documentElement

In all current engines.

Firefox1+Safari1+Chrome1+ Opera7+Edge79+ Edge (Legacy)12+IE5+ Firefox for Android4+iOS Safari1+Chrome for Android18+Android WebView1+Samsung Internet1.0+Opera Mobile10.1+

The documentElement getter steps are to return this’s document element.

Document/getElementsByTagName

In all current engines.

Firefox1+Safari1+Chrome1+ Opera5.1+Edge79+ Edge (Legacy)12+IE5+ Firefox for Android4+iOS Safari1+Chrome for Android18+Android WebView1+Samsung Internet1.0+Opera Mobile10.1+

The getElementsByTagName(qualifiedName) method steps are to return the list of elements with qualified name qualifiedName for this.

Thus, in an HTML document, document.getElementsByTagName("FOO") will match <FOO> elements that are not in the HTML namespace, and <foo> elements that are in
the HTML namespace, but not <FOO> elements
that are in the HTML namespace.

Document/getElementsByTagNameNS

In all current engines.

Firefox1+Safari1+Chrome1+ Opera12.1+Edge79+ Edge (Legacy)12+IE9+ Firefox for Android4+iOS Safari1+Chrome for Android18+Android WebView1+Samsung Internet1.0+Opera Mobile12.1+

The getElementsByTagNameNS(namespace, localName) method steps are to return the list of elements with namespace namespace and local
name localName
for Given the following XHTML fragment:

<div id="example"> <p id="p1" class="aaa bbb"/> <p id="p2" class="aaa ccc"/> <p id="p3" class="bbb ccc"/>
</div>

A call to document.getElementById("example").getElementsByClassName("aaa") would return a HTMLCollection with the two paragraphs p1 and p2 in it.

A call to getElementsByClassName("ccc bbb") would only return one node, however, namely p3. A call to document.getElementById("example").getElementsByClassName("bbb  ccc ") would return the same thing.

A call to getElementsByClassName("aaa,bbb") would return no nodes; none of the elements above are in the aaa,bbb class.

Report Page