-
Notifications
You must be signed in to change notification settings - Fork 22.5k
/
index.md
58 lines (39 loc) · 1.21 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
58
---
title: "Attr: value property"
short-title: value
slug: Web/API/Attr/value
page-type: web-api-instance-property
browser-compat: api.Attr.value
---
{{APIRef("DOM")}}
The **`value`** property of the {{domxref("Attr")}} interface contains the value of the attribute.
## Value
A string representing the attribute value.
## Example
The following example displays the current value of the attribute `test`. Clicking on the button will change it to a different value, and read it again to update the displayed value.
### HTML
```html
<label test="initial value"></label>
<button>Click me to set test to <code>"a new value"</code>…</button>
<p>
Current value of the <code>test</code> attribute:
<output id="result">None.</output>
</p>
```
### JavaScript
```js
const element = document.querySelector("label");
const button = document.querySelector("button");
const result = document.querySelector("#result");
const attribute = element.attributes[0];
result.value = attribute.value;
button.addEventListener("click", () => {
attribute.value = "a new value";
result.value = attribute.value;
});
```
{{ EmbedLiveSample('Example','100%',100) }}
## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}