Este tipo representa un atributo de un elemento DOM como un objeto. En muchos m茅todos DOM, probablemente vas a obtener el atributo como una cadena (e.g., Element.getAttribute()
, pero algunas funciones (e.g., Element.getAttributeNode()
) or means of iterating give Attr
types.
<div id="interfaceDiagram" style="display: inline-block; position: relative; width: 100%; padding-bottom: 11.666666666666666%; vertical-align: middle; overflow: hidden;"><svg style="display: inline-block; position: absolute; top: 0; left: 0;" viewbox="-50 0 600 70" preserveAspectRatio="xMinYMin meet"><a xlink:href="https://developer.mozilla.org/es/docs/Web/API/EventTarget" target="_top"><rect x="1" y="1" width="110" height="50" fill="#fff" stroke="#D4DDE4" stroke-width="2px" /><text x="56" y="30" font-size="12px" font-family="Consolas,Monaco,Andale Mono,monospace" fill="#4D4E53" text-anchor="middle" alignment-baseline="middle">EventTarget</text></a><polyline points="111,25 121,20 121,30 111,25" stroke="#D4DDE4" fill="none"/><line x1="121" y1="25" x2="151" y2="25" stroke="#D4DDE4"/><a xlink:href="https://developer.mozilla.org/es/docs/Web/API/Node" target="_top"><rect x="151" y="1" width="75" height="50" fill="#fff" stroke="#D4DDE4" stroke-width="2px" /><text x="188.5" y="30" font-size="12px" font-family="Consolas,Monaco,Andale Mono,monospace" fill="#4D4E53" text-anchor="middle" alignment-baseline="middle">Node</text></a><polyline points="226,25 236,20 236,30 226,25" stroke="#D4DDE4" fill="none"/><line x1="236" y1="25" x2="266" y2="25" stroke="#D4DDE4"/><a xlink:href="https://developer.mozilla.org/es/docs/Web/API/Attr" target="_top"><rect x="266" y="1" width="75" height="50" fill="#F4F7F8" stroke="#D4DDE4" stroke-width="2px" /><text x="303.5" y="30" font-size="12px" font-family="Consolas,Monaco,Andale Mono,monospace" fill="#4D4E53" text-anchor="middle" alignment-baseline="middle">Attr</text></a></svg></div>
a:hover text { fill: #0095DD; pointer-events: all;}
Advertencia:En el DOM Core 1, 2 y 3,
Attr
se hereda del Node
. Este ya no es el caso en DOM4.Para llevar la implementaci贸n de Attr a la especifiaci贸n, se esta trabajando para cambiarlo y dejar de heredar deNode
. No debe de utilizar ninguna propiedad o m茅todo de nodo en los objetos Attr
. A partir de Gecko 7.0 (Firefox 7.0 / Thunderbird 7.0 / SeaMonkey 2.4), los que se eliminar谩n enviar谩n mensajes de advertencia a la consola. Debe revisar su c贸digo en consecuencia. Consulte Propiedades y m茅todos en desuso para obtener una lista completa.Propiedades
name
Read only- El nombre del atributo.
namespaceURI
Read only- Un
DOMString
representing the namespace URI of the attribute, ornull
if there is no namespace. localName
Read only- A
DOMString
representing the local part of the qualified name of the attribute. prefix
Read only- A
DOMString
representing the namespace prefix of the attribute, ornull
if no prefix is specified. specified
Read only- This property always returns
true
. Originally, it returnedtrue
if the attribute was explicitly specified in the source code or by a script, andfalse
if its value came from the default one defined in the document's DTD. value
- El valor del atributo.
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.
Propiedades y m茅todos obsoletos
Las siguientes propiedades son obsoletos. Where available, the appropriate replacement is provided.
attributes
- Este propiedad ahora siempre devuelve
NULL
. childNodes
- Este propiedad ahora siempre devuelve
NULL
. firstChild
- Este propiedad ahora siempre devuelve
NULL
. isId
Read only- 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
- Este propiedad ahora siempre devuelve
NULL
. nextSibling
- Este propiedad ahora siempre devuelve
NULL
. nodeName
- Utilizar
Attr.name
en su lugar. nodeType
- Esta propiedad ahora siempre devuelve 2 (
ATTRIBUTE_NODE
). nodeValue
- Utilizar
Attr.value
en su lugar. ownerDocument
- Seguramente nunca usaste esta propiedad asi que no deberias preocuparte si esque ya no est谩 disponible.
ownerElement
Desaprobado Gecko 7.0 Obsoleto Gecko 29.0 Read only- Since you get an
Attr
object from anElement
, you should already know the associated element. - Contrary to above claim,
Document.evaluate
can returnAttr
objects from an XPath, in which case you would not easily know the owner. parentNode
- Estra propiedad ahora siempre devuelve
NULL
. previousSibling
- Estra propiedad ahora siempre devuelve
NULL
. schemaTypeInfo
Read only- 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
- Estra propiedad ahora siempre devuelve
true
. textContent
- Utilizar
Attr.value
en su lugar.
Los siguientes metodos ahora son obsoletos.
appendChild()
- Modify the value of
Attr.value
instead. cloneNode()
- Seguramente nunca usaste esta propiedad asi que no deberias preocuparte si esque ya no est谩 disponible.
createAttribute()
- Use
Element.setAttribute()
instead. createAttributeNS()
- Use
Element.setAttributeNS()
instead. getAttributeNode()
- Use
Element.getAttribute()
instead. getAttributeNodeNS()
- Use
Element.getAttributeNS()
instead. hasAttributes()
Obsoleto Gecko 21.0- Estra propiedad ahora retorna false.
hasChildNodes()
- Estra propiedad ahora devuelve
false
. insertBefore()
- Modify the value of
Attr.value
instead. isSupported()
- Seguramente nunca usaste esta propiedad asi que no deberias preocuparte si esque ya no est谩 disponible.
isEqualNode()
- Seguramente nunca usaste esta propiedad asi que no deberias preocuparte si esque ya no est谩 disponible.
normalize()
- Seguramente nunca usaste esta propiedad asi que no deberias preocuparte si esque ya no est谩 disponible.
removeAttributeNode()
- Use
Element.removeAttribute()
instead. removeChild()
- Modify the value of
Attr.value
instead. replaceChild()
- Modify the value of
Attr.value
instead. setAttributeNode()
- Use
Element.setAttribute()
instead. setAttributeNodeNS()
- Use
Element.setAttributeNS()
instead.
Especificaciones
Especificaci贸n | Estado | Comentario |
---|---|---|
DOM4 La definici贸n de 'Attr' en esta especificaci贸n. |
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 La definici贸n de 'Attr' en esta especificaci贸n. |
Obsolete | Definici贸n inicial |
Compatibilidad con navegadores
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 | Firefox (Gecko) | Internet Explorer | Opera | Safari |
---|---|---|---|---|---|
Basic support | (Yes)[1] | (Yes) | (Yes) | (Yes) | (Yes) |
Feature | Android | Android Webview | Firefox Mobile (Gecko) | IE Mobile | Opera Mobile | Safari Mobile | Chrome for Android |
---|---|---|---|---|---|---|---|
Basic support | (Yes) | (Yes) [1] | (Yes) | (Yes) | (Yes) | (Yes) | (Yes)[1] |
[1] As of Chrome 45, this property no longer inherits from Node.