Movatterモバイル変換


[0]ホーム

URL:


  1. Web
  2. Web APIs
  3. Attr

Attr

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.

TheAttr interface represents one of an element's attributes as an object. In most situations, you will directly retrieve the attribute value as a string (e.g.,Element.getAttribute()), but some cases may require interacting withAttr instances (e.g.,Element.getAttributeNode()).

EventTarget Node Attr

The core idea of an object of typeAttr is the association between aname and avalue. An attribute may also be part of anamespace and, in this case, it also has a URI identifying the namespace, and a prefix that is an abbreviation for the namespace.

The name is deemedlocal when it ignores the eventual namespace prefix and deemedqualified when it includes the prefix of the namespace, if any, separated from the local name by a colon (:). We have three cases: an attribute outside of a namespace, an attribute inside a namespace without a prefix defined, an attribute inside a namespace with a prefix:

AttributeNamespace nameNamespace prefixAttribute local nameAttribute qualified name
myAttrnonenonemyAttrmyAttr
myAttrmynamespacenonemyAttrmyAttr
myAttrmynamespacemynsmyAttrmyns:myAttr

Note:This interface represents only attributes present in the tree representation of theElement, being a SVG, an HTML or a MathML element. It doesn't represent theproperty of an interface associated with such element, such asHTMLTableElement for a<table> element. (Seethis article for more information about attributes and how they arereflected into properties.)

Instance properties

This interface also inherits the properties of its parent interfaces,Node andEventTarget.

localNameRead only

A string representing the local part of the qualified name of the attribute.

nameRead only

The attribute'squalified name. If the attribute is not in a namespace, it will be the same aslocalName property.

namespaceURIRead only

A string representing the URI of the namespace of the attribute, ornull if there is no namespace.

ownerElementRead only

TheElement the attribute belongs to.

prefixRead only

A string representing the namespace prefix of the attribute, ornull if a namespace without prefix or no namespace are specified.

specifiedRead onlyDeprecated

This property always returnstrue.

value

The attribute's value, a string that can be set and get using this property.

Instance methods

This interface has no specific methods, but inherits the methods of its parent interfaces,Node andEventTarget.

Specifications

Specification
DOM
# interface-attr

Browser compatibility

See also

Help improve MDN

Learn how to contribute

This page was last modified on byMDN contributors.


[8]ページ先頭

©2009-2026 Movatter.jp