DOM

DOM

Source

Elements also have an associated shadow root (null or a shadow root). It is null unless otherwise stated. An element is a shadow host if its shadow root is non-null.

An element’s qualified name is its local name if its namespace prefix is null; otherwise its namespace prefix, followed by ":", followed by its local name.

An element’s HTML-uppercased qualified name is the return
value of these steps:

User agents could optimize qualified name and HTML-uppercased qualified name by storing them in internal slots.

To create an element,
given a document, localName, namespace, and optional prefix, is, and synchronous custom elements flag, run these steps:

  1. If prefix was not given, let prefix be null.

  2. If is was not given, let is be null.

  3. Let result be null.

  4. Let definition be the result of looking up a custom element definition given document, namespace, localName, and is.

  5. If definition is non-null, and definition’s name is not equal to its local name (i.e., definition represents a customized built-in element), then:

    1. Let interface be the element interface for localName and the HTML namespace.

    2. Set result to a new element that implements interface, with no attributes, namespace set to the HTML namespace, namespace prefix set to prefix, local name set to localName, custom element state set to "undefined", custom element definition set to null, is value set to is, and node document set to document.

    3. If the synchronous custom elements flag is set, then run this step while catching any exceptions:

      1. Upgrade element using definition.

      If this step threw an exception, then:

      1. Report the exception.

      2. Set result’s custom element state to "failed".

    4. Otherwise, enqueue a custom element upgrade reaction given result and definition.

  6. Otherwise, if definition is non-null, then:

    1. If the synchronous custom elements flag is set, then run these steps while catching any exceptions:

      If any of these steps threw an exception, then:

    2. Otherwise:

  7. Otherwise:

    1. Let interface be the element interface for localName and namespace.

    2. Set result to a new element that implements interface, with no attributes, namespace set to namespace, namespace prefix set to prefix, local name set to localName, custom element state set to "uncustomized", custom element definition set to null, is value set to is, and node document set to document.

    3. If namespace is the HTML namespace, and either localName is a valid custom element name or is is non-null, then set result’s custom element state to "undefined".

  8. Return result.

Elements also have an attribute list, which is a list exposed through a NamedNodeMap. Unless explicitly given when an element is created, its attribute list is empty.

An element has an attribute A if its attribute list contains A.

This and other specifications may define attribute change steps for elements. The algorithm is passed element, localName, oldValue, value, and namespace.

To handle attribute changes for an attribute attribute with element, oldValue, and newValue, run these steps:

  1. Queue a mutation record of "attributes" for element with attribute’s local name, attribute’s namespace, oldValue, « », « », null, and null.

  2. If element is custom, then enqueue a custom element callback reaction with element, callback name "attributeChangedCallback", and an argument list containing attribute’s local name, oldValue, newValue, and attribute’s namespace.

  3. Run the attribute change steps with element, attribute’s local name, oldValue, newValue, and attribute’s namespace.

To change an attribute attribute to value, run these steps:

To append an attribute attribute to an element element, run these
steps:

To an attribute attribute, run these steps:

To replace an attribute oldAttr with an attribute newAttr, run these steps:

To get an attribute by name given a qualifiedName and element element, run these steps:

To get an attribute by namespace and local name given a namespace, localName, and element element,
run these steps:

To get an attribute value given an element element, localName, and optionally a namespace (null unless stated otherwise), run these steps:

  1. Let attr be the result of getting an attribute given namespace, localName, and element.

  2. If attr is null, then return the empty string.

  3. Return attr’s value.

To set an attribute given an attr and element, run these steps:

To set an attribute value for an element element, using a localName and value, and an
optional prefix, and namespace, run these steps:

  1. If prefix is not given, set it to null.
  2. If namespace is not given, set it to null.
  3. Let attribute be the result of getting an attribute given namespace, localName, and element.
  4. If attribute is null, create an attribute whose namespace is namespace, namespace prefix is prefix, local name is localName, value is value, and node document is element’s node document, then append this attribute to element, and then return.
  5. Change attribute to value.

To given a qualifiedName and element element, run these steps:

  1. Let attr be the result of getting an attribute given qualifiedName and element.

  2. If attr is non-null, then remove attr.

  3. Return attr.

To given a namespace, localName, and element element,
run these steps:

  1. Let attr be the result of getting an attribute given namespace, localName, and element.

  2. If attr is non-null, then remove attr.

  3. Return attr.

An element can have an associated unique identifier (ID)

Historically elements could have multiple identifiers e.g., by using
the HTML id attribute and a DTD. This specification makes ID a concept of the DOM and allows for only one per element, given by an id attribute.

Use these attribute change steps to update an element’s ID:

  1. If localName is id, namespace is null, and value is null or the empty string, then unset element’s ID.

  2. Otherwise, if localName is id, namespace is null, then set element’s ID to value.

While this specification defines requirements for class, id, and slot attributes on any element, it makes no
claims as to whether using them is conforming or not.

A node’s parent of type Element is known as a parent element. If the node has a parent of a different type, its parent element is null.

namespace = element . namespaceURI Returns the namespace. prefix = element . prefix Returns the namespace prefix. localName = element . localName Returns the local name. qualifiedName = element . tagName Returns the HTML-uppercased qualified name.

Element/namespaceURI

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 namespaceURI getter steps are to return this’s namespace.

Element/prefix

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 prefix getter steps are to return this’s namespace prefix.

Element/localName

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 localName getter steps are to return this’s local name.

Element/tagName

In all current engines.

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

The tagName getter steps are to return this’s HTML-uppercased qualified name.

element . id [ = value ]

Returns the value of element’s id content attribute. Can be set to change it.

element . className [ = value ]

Returns the value of element’s class content attribute. Can be set to change it.

element . classList

Allows for manipulation of element’s class content attribute as a set of whitespace-separated tokens through a DOMTokenList object.

element . slot [ = value ]

Returns the value of element’s slot content attribute. Can be set to change it.

IDL attributes that are defined to reflect a
content attribute of a given name, must have a getter and setter that follow these
steps:

getter

Return the result of running get an attribute value given this and name.

setter

Set an attribute value for this using name and the given value.

Element/id

In all current engines.

Firefox1+Safari1+Chrome23+ Opera12.1+Edge79+ Edge (Legacy)12+IE5+ Firefox for Android4+iOS Safari1+Chrome for Android25+Android WebView37+Samsung Internet1.5+Opera Mobile12.1+

The id attribute must reflect the
"id" content attribute.

Element/className

In all current engines.

Firefox1+Safari1+Chrome22+ Opera8+Edge79+ Edge (Legacy)12+IE5+ Firefox for Android4+iOS Safari1+Chrome for Android25+Android WebView37+Samsung Internet1.5+Opera Mobile10.1+

The className attribute must reflect the "class" content attribute.

Element/classList

In all current engines.

Firefox3.6+Safari6.1+Chrome22+ Opera11.5+Edge79+ Edge (Legacy)16+IENone Firefox for Android4+iOS Safari7+Chrome for Android25+Android WebView4.4+Samsung Internet1.5+Opera Mobile11.5+

The classList getter steps are to return a DOMTokenList object whose associated element is this and whose associated attribute’s local name is class. The token set of this
particular DOMTokenList object are also known as the element’s classes.



Read Next page

Report Page