-
Notifications
You must be signed in to change notification settings - Fork 22.4k
/
index.md
57 lines (37 loc) · 1.66 KB
/
index.md
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
---
title: "Element: getAttributeNode() method"
short-title: getAttributeNode()
slug: Web/API/Element/getAttributeNode
page-type: web-api-instance-method
browser-compat: api.Element.getAttributeNode
---
{{ APIRef("DOM") }}
Returns the specified attribute of the specified element, as an {{domxref("Attr")}} node.
This method is useful if you need the attribute's [instance properties](/en-US/docs/Web/API/Attr#instance_properties).
If you only need the attribute's value, you can use the {{domxref("Element.getAttribute()", "getAttribute()")}} method instead.
## Syntax
```js-nolint
getAttributeNode(attrName)
```
### Parameters
- `attrName` is a string containing the name of the attribute.
### Return value
An `Attr` node for the attribute.
## Examples
```js
// html: <div id="top" />
let t = document.getElementById("top");
let idAttr = t.getAttributeNode("id");
alert(idAttr.value === "top");
```
## Notes
When called on an HTML element in a DOM flagged as an HTML document, `getAttributeNode` lower-cases its argument before proceeding.
The `Attr` node inherits from `Node`, but is not considered a part of the document tree. Common `Node` attributes like [parentNode](/en-US/docs/Web/API/Node/parentNode), [previousSibling](/en-US/docs/Web/API/Node/previousSibling), and [nextSibling](/en-US/docs/Web/API/Node/nextSibling) are `null` for an `Attr` node. You can, however, get the element to which the attribute belongs with the `ownerElement` property.
## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}
## See also
- {{domxref("Document.createAttribute()")}}
- {{domxref("Element.setAttributeNode()")}}
- {{domxref("Element.removeAttributeNode()")}}