Skip to content

Commit 4b957ac

Browse files
authored
Update article.md
1 parent 4b02949 commit 4b957ac

File tree

1 file changed

+8
-8
lines changed
  • 2-ui/1-document/06-dom-attributes-and-properties

1 file changed

+8
-8
lines changed

2-ui/1-document/06-dom-attributes-and-properties/article.md

+8-8
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ When the browser loads the page, it "reads" (another word: "parses") HTML text a
44

55
For instance, if the tag is `<body id="page">`, then the DOM object has `body.id="page"`.
66

7-
But the attribute-property mapping is not one-to-one! In this chapter we'll pay attention to separate these two notions, to see how to work with them, when they are same, and when they are different.
7+
But the attribute-property mapping is not one-to-one! In this chapter we'll pay attention to separate these two notions, to see how to work with them, when they are the same, and when they are different.
88

99
[cut]
1010

@@ -28,11 +28,11 @@ alert(document.body.myData.title); // Imperator
2828
We can add a method as well:
2929

3030
```js run
31-
document.body.sayHi = function() {
31+
document.body.sayTagName = function() {
3232
alert(this.tagName);
3333
};
3434

35-
document.body.sayHi(); // BODY (the value of "this" in the method is document.body)
35+
document.body.sayTagName(); // BODY (the value of "this" in the method is document.body)
3636
```
3737

3838
We can also modify built-in prototypes like `Element.prototype` and add new methods to all elements:
@@ -129,7 +129,7 @@ Here's an extended demo of working with attributes:
129129
alert( elem.outerHTML ); // (3), see it's there
130130
131131
for (let attr of elem.attributes) { // (4) list all
132-
alert( attr.name + " = " + attr.value );
132+
alert( `${attr.name} = ${attr.value}` );
133133
}
134134
</script>
135135
</body>
@@ -144,9 +144,9 @@ Please note:
144144

145145
## Property-attribute synchronization
146146

147-
When a standard attribute changes, the corresponding property is auto-updated, and (with some exceptions) vise-versa.
147+
When a standard attribute changes, the corresponding property is auto-updated, and (with some exceptions) vice versa.
148148

149-
In the example below `id` is modified as an attribute, and we can see the property change too. And then the same backwards:
149+
In the example below `id` is modified as an attribute, and we can see the property changed too. And then the same backwards:
150150

151151
```html run
152152
<input>
@@ -188,7 +188,7 @@ In the example above:
188188
- Changing the attribute `value` updates the property.
189189
- But the property change does not affect the attribute.
190190

191-
That "feature" may actually can come in handy, because the user may modify `value`, and then after it, if we want to recover the "original" value from HTML, it's in the attribute.
191+
That "feature" may actually come in handy, because the user may modify `value`, and then after it, if we want to recover the "original" value from HTML, it's in the attribute.
192192

193193
## DOM properties are typed
194194

@@ -311,7 +311,7 @@ div.setAttribute('order-state', 'canceled');
311311

312312
But there may be a possible problem with custom attributes. What if we use a non-standard attribute for our purposes and later the standard introduces it and makes it do something? The HTML language is alive, it grows, more attributes appear to suit the needs of developers. There may be unexpected effects in such case.
313313

314-
To evade conflicts, there exist [data-*](https://html.spec.whatwg.org/#embedding-custom-non-visible-data-with-the-data-*-attributes) attributes.
314+
To avoid conflicts, there exist [data-*](https://html.spec.whatwg.org/#embedding-custom-non-visible-data-with-the-data-*-attributes) attributes.
315315

316316
**All attributes starting with "data-" are reserved for programmers' use. They are available in `dataset` property.**
317317

0 commit comments

Comments
 (0)