This type represents a DOM element's attribute as an object. In most DOM methods, you will probably directly retrieve the attribute as a string (e.g., Element.getAttribute()
, but certain functions (e.g., Element.getAttributeNode()
) or means of iterating give Attr
types.
name
Read only
namespaceURI
Read only
DOMString
representing the namespace URI of the attribute, or null
if there is no namespace.localName
Read only
DOMString
representing the local part of the qualified name of the attribute.prefix
Read only
DOMString
representing the namespace prefix of the attribute, or null
if no prefix is specified.ownerElement
Read only
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
Read only
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
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.
The following properties have been deprecated. Where available, the appropriate replacement is provided.
attributes
NULL
.childNodes
Obsolete since Gecko 14
NodeList
.firstChild
Obsolete since Gecko 14
NULL
.isId
Read only
lastChild
Obsolete since Gecko 14
NULL
.nextSibling
NULL
.nodeName
Attr.name
instead.nodeType
ATTRIBUTE_NODE
).nodeValue
Attr.value
instead.ownerDocument
parentNode
NULL
.previousSibling
NULL
.schemaTypeInfo
Read only
Document.normalizeDocument
, this property may not be reliable if the node was moved.specified
true
.textContent
Attr.value
instead.The following methods have been deprecated:
appendChild()
Obsolete since Gecko 14
Attr.value
instead.cloneNode()
createAttribute()
Element.setAttribute()
instead.createAttributeNS()
Element.setAttributeNS()
instead.getAttributeNode()
Element.getAttribute()
instead.getAttributeNodeNS()
Element.getAttributeNS()
instead.hasAttributes()
Obsolete since Gecko 21.0
hasChildNodes()
insertBefore()
Attr.value
instead.isSupported()
isEqualNode()
normalize()
removeAttributeNode()
Element.removeAttribute()
instead.removeChild()
Obsolete since Gecko 14
Attr.value
instead.replaceChild()
Obsolete since Gecko 14
Attr.value
instead.setAttributeNode()
Element.setAttribute()
instead.setAttributeNodeNS()
Element.setAttributeNS()
instead.Specification | Status | Comment |
---|---|---|
DOM The definition of 'Attr' in that specification. | Living Standard | Added ownerElement property back |
DOM4 The definition of 'Attr' in that specification. | Obsolete | Moved namespaceURI , prefix and localName from Node to this API and removed ownerElement , schemaTypeInfo and isId . |
Document Object Model (DOM) Level 3 Core Specification The definition of 'Attr' in that specification. | Obsolete | Initial definition |
Feature | Chrome | Edge | Firefox (Gecko) | Internet Explorer | Opera | Safari |
---|---|---|---|---|---|---|
Basic support | (Yes)[1] | (Yes) | (Yes) | (Yes) | (Yes) | (Yes) |
Feature | Android | Android Webview | Edge | Firefox Mobile (Gecko) | IE Mobile | Opera Mobile | Safari Mobile | Chrome for Android |
---|---|---|---|---|---|---|---|---|
Basic support | (Yes) | (Yes)[1] | (Yes) | (Yes) | (Yes) | (Yes) | (Yes) | (Yes)[1] |
[1] As of Chrome 45, this property no longer inherits from Node.
© 2005–2018 Mozilla Developer Network and individual contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/Attr