Skip to content

Commit ffee629

Browse files
authored
Merge pull request #399 from brentguf/attributes-properties
Attributes/properties
2 parents 9365275 + e83b8d0 commit ffee629

File tree

1 file changed

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

1 file changed

+9
-9
lines changed

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

+9-9
Original file line numberDiff line numberDiff line change
@@ -108,10 +108,10 @@ Here's a demo of reading a non-standard property:
108108
</body>
109109
```
110110

111-
HTML attributes have following features:
111+
HTML attributes have the following features:
112112

113-
- Their name is case-insensitive (that's HTML: `id` is same as `ID`).
114-
- They are always strings.
113+
- Their name is case-insensitive (`id` is same as `ID`).
114+
- Their values are always strings.
115115

116116
Here's an extended demo of working with attributes:
117117

@@ -136,7 +136,7 @@ Here's an extended demo of working with attributes:
136136
Please note:
137137

138138
1. `getAttribute('About')` -- the first letter is uppercase here, and in HTML it's all lowercase. But that doesn't matter: attribute names are case-insensitive.
139-
2. We can assign anything to an attribute, but that becomes a string. So here we have `"123"` as the value.
139+
2. We can assign anything to an attribute, but it becomes a string. So here we have `"123"` as the value.
140140
3. All attributes including ones that we set are visible in `outerHTML`.
141141
4. The `attributes` collection is iterable and has all attributes with `name` and `value`.
142142

@@ -190,7 +190,7 @@ That "feature" may actually come in handy, because the user may modify `value`,
190190

191191
## DOM properties are typed
192192

193-
DOM properties are not always strings. For instance, `input.checked` property (for checkboxes) is boolean:
193+
DOM properties are not always strings. For instance, the `input.checked` property (for checkboxes) is a boolean:
194194

195195
```html run
196196
<input id="input" type="checkbox" checked> checkbox
@@ -201,7 +201,7 @@ DOM properties are not always strings. For instance, `input.checked` property (f
201201
</script>
202202
```
203203

204-
There are other examples. The `style` attribute is a string, but `style` property is an object:
204+
There are other examples. The `style` attribute is a string, but the `style` property is an object:
205205

206206
```html run
207207
<div id="div" style="color:red;font-size:120%">Hello</div>
@@ -311,7 +311,7 @@ But there may be a possible problem with custom attributes. What if we use a non
311311

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

314-
**All attributes starting with "data-" are reserved for programmers' use. They are available in `dataset` property.**
314+
**All attributes starting with "data-" are reserved for programmers' use. They are available in the `dataset` property.**
315315

316316
For instance, if an `elem` has an attribute named `"data-about"`, it's available as `elem.dataset.about`.
317317

@@ -380,7 +380,7 @@ Methods to work with attributes are:
380380
- `elem.removeAttribute(name)` -- to remove the attribute.
381381
- `elem.attributes` is a collection of all attributes.
382382

383-
For most needs DOM properties can serve us well. We should refer to attributes only when DOM properties do not suit us, when we need exactly attributes, for instance:
383+
For most needs, DOM properties can serve us well. We should refer to attributes only when DOM properties do not suit us, when we need exactly attributes, for instance:
384384

385385
- We need a non-standard attribute. But if it starts with `data-`, then we should use `dataset`.
386-
- We want to read the value "as written" in HTML. The value of the DOM property may be different, for instance `href` property is always a full URL, and we may want to get the "original" value.
386+
- We want to read the value "as written" in HTML. The value of the DOM property may be different, for instance the `href` property is always a full URL, and we may want to get the "original" value.

0 commit comments

Comments
 (0)