We're looking for a user researcher to understand the needs of developers and designers. Is this you or someone you know? Check out the post: https://mzl.la/2IGzdXS

Перевод не завершен. Пожалуйста, помогите перевести эту статью с английского.

Этот тип представляет атрибут элемента DOM в виде объекта. В большинстве методов DOM вы, вероятно, непосредственно извлекаете атрибут в виде строки (например, Element.getAttribute (), но некоторые функции (например, Element.getAttributeNode ()) или средства итерации, отдают тип Attr.

Warning: Starting in Gecko 7.0 (Firefox 7.0 / Thunderbird 7.0 / SeaMonkey 2.4), the ones that are going to be removed output warning messages to the console. You should revise your code accordingly. See Deprecated properties and methods for a complete list.

Properties

name Только для чтения
Имя аттрибута.
namespaceURI Только для чтения
A DOMString representing the namespace URI of the attribute, or null if there is no namespace.
localName Только для чтения
A DOMString representing the local part of the qualified name of the attribute.
prefix Только для чтения
A DOMString representing the namespace prefix of the attribute, or null if no prefix is specified.
ownerElement Только для чтения

The element holding the attribute.

Note: DOM Level 4 removed this property. The assumption was that since you get an Attr object from an Element, you should already know the associated element.
As that doesn't hold true in cases like Attr objects being returned by Document.evaluate, the DOM Living Standard reintroduced the property.

Gecko outputs a deprecation note starting from Gecko 7.0 (Firefox 7.0 / Thunderbird 7.0 / SeaMonkey 2.4). This note was removed again in Gecko 49.0 (Firefox 49.0 / Thunderbird 49.0 / SeaMonkey 2.46).

specified Только для чтения
This property always returns true. Originally, it returned true if the attribute was explicitly specified in the source code or by a script, and false if its value came from the default one defined in the document's DTD.
value
The attribute's value.

Note: DOM Level 3 defined namespaceURI, localName and prefix on the Node interface. In DOM4 they were moved to Attr.

This change is implemented in Chrome since version 46.0 and Firefox since version 48.0.

Deprecated properties and methods

The following properties have been deprecated. Where available, the appropriate replacement is provided.

attributes
This property now always returns NULL.
childNodes Вышла из употребления с версии Gecko 14
This property now always returns an empty NodeList.
firstChild Вышла из употребления с версии Gecko 14
This property now always returns NULL.
isId Только для чтения
Indicates whether the attribute is an "ID attribute". An "ID attribute" being an attribute which value is expected to be unique across a DOM Document. In HTML DOM, "id" is the only ID attribute, but XML documents could define others. Whether or not an attribute is unique is often determined by a DTD or other schema description.
lastChild Вышла из употребления с версии Gecko 14
This property now always returns NULL.
nextSibling
This property now always returns NULL.
nodeName
Use Attr.name instead.
nodeType
This property now always returns 2 (ATTRIBUTE_NODE).
nodeValue
Use Attr.value instead.
ownerDocument
You shouldn't have been using this in the first place, so you probably don't care that this is going away.
parentNode
This property now always returns NULL.
previousSibling
This property now always returns NULL.
schemaTypeInfo Только для чтения
The type information associated with this attribute. While the type information contained in this attribute is guaranteed to be correct after loading the document or invoking Document.normalizeDocument, this property may not be reliable if the node was moved.
specified
This property now always returns true.
textContent
Use Attr.value instead.

The following methods have been deprecated:

appendChild() Вышла из употребления с версии Gecko 14
Modify the value of Attr.value instead.
cloneNode()
You shouldn't have been using this in the first place, so you probably don't care that this is going away.
createAttribute()
Use Element.setAttribute() instead.
createAttributeNS()
Use Element.setAttributeNS() instead.
getAttributeNode()
Use Element.getAttribute() instead.
getAttributeNodeNS()
Use Element.getAttributeNS() instead.
hasAttributes() Вышла из употребления с версии Gecko 21.0
This method now always returns false.
hasChildNodes()
This method now always returns false.
insertBefore()
Modify the value of Attr.value instead.
isSupported()
You shouldn't have been using this in the first place, so you probably don't care that this is going away.
isEqualNode()
You shouldn't have been using this in the first place, so you probably don't care that this is going away.
normalize()
You shouldn't have been using this in the first place, so you probably don't care that this is going away.
removeAttributeNode()
Use Element.removeAttribute() instead.
removeChild() Вышла из употребления с версии Gecko 14
Modify the value of Attr.value instead.
replaceChild() Вышла из употребления с версии Gecko 14
Modify the value of Attr.value instead.
setAttributeNode()
Use Element.setAttribute() instead.
setAttributeNodeNS()
Use Element.setAttributeNS() instead.

Specifications

Specification Status Comment
DOM
Определение 'Attr' в этой спецификации.
Живой стандарт Added ownerElement property back
DOM4
Определение 'Attr' в этой спецификации.
Устаревшая Moved namespaceURI, prefix and localName from Node to this API and removed ownerElement, schemaTypeInfo and isId.
Document Object Model (DOM) Level 3 Core Specification
Определение 'Attr' в этой спецификации.
Устаревшая Initial definition

Поддержка браузерами

We're converting our compatibility data into a machine-readable JSON format. This compatibility table still uses the old format, because we haven't yet converted the data it contains. Find out how you can help!

Feature Chrome Edge Firefox (Gecko) Internet Explorer Opera Safari
Базовая поддержка (Да)[1] (Да) (Да) (Да) (Да) (Да)
Feature Android Android Webview Edge Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile Chrome for Android
Базовая поддержка (Да) (Да)[1] (Да) (Да) (Да) (Да) (Да) (Да)[1]

[1] Начиная с Chrome 45, это свойство больше не наследуется от Node.

Метки документа и участники

Внесли вклад в эту страницу: dieillusion
Обновлялась последний раз: dieillusion,