|
1 | 1 | # Attributes and properties
|
2 | 2 |
|
3 |
| -When the browser loads the page, it "reads" (another word: "parses") HTML text and generates DOM objects from it. For element nodes most standard HTML attributes automatically become properties of DOM objects. |
| 3 | +When the browser loads the page, it "reads" (another word: "parses") the HTML and generates DOM objects from it. For element nodes, most standard HTML attributes automatically become properties of DOM objects. |
4 | 4 |
|
5 | 5 | For instance, if the tag is `<body id="page">`, then the DOM object has `body.id="page"`.
|
6 | 6 |
|
@@ -51,7 +51,7 @@ So, DOM properties and methods behave just like those of regular JavaScript obje
|
51 | 51 |
|
52 | 52 | ## HTML attributes
|
53 | 53 |
|
54 |
| -In HTML language, tags may have attributes. When the browser reads HTML text and creates DOM objects for tags, it recognizes *standard* attributes and creates DOM properties from them. |
| 54 | +In HTML, tags may have attributes. When the browser parses the HTML to create DOM objects for tags, it recognizes *standard* attributes and creates DOM properties from them. |
55 | 55 |
|
56 | 56 | So when an element has `id` or another *standard* attribute, the corresponding property gets created. But that doesn't happen if the attribute is non-standard.
|
57 | 57 |
|
@@ -83,9 +83,9 @@ Here we can see it:
|
83 | 83 | </body>
|
84 | 84 | ```
|
85 | 85 |
|
86 |
| -So, if an attribute is non-standard, there won't be DOM-property for it. Is there a way to access such attributes? |
| 86 | +So, if an attribute is non-standard, there won't be a DOM-property for it. Is there a way to access such attributes? |
87 | 87 |
|
88 |
| -Sure. All attributes are accessible using following methods: |
| 88 | +Sure. All attributes are accessible by using the following methods: |
89 | 89 |
|
90 | 90 | - `elem.hasAttribute(name)` -- checks for existence.
|
91 | 91 | - `elem.getAttribute(name)` -- gets the value.
|
@@ -138,7 +138,7 @@ Please note:
|
138 | 138 | 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 | 139 | 2. We can assign anything to an attribute, but it becomes a string. So here we have `"123"` as the value.
|
140 | 140 | 3. All attributes including ones that we set are visible in `outerHTML`.
|
141 |
| -4. The `attributes` collection is iterable and has all attributes with `name` and `value`. |
| 141 | +4. The `attributes` collection is iterable and has all the attributes of the element (standard and non-standard) as objects with `name` and `value` properties. |
142 | 142 |
|
143 | 143 | ## Property-attribute synchronization
|
144 | 144 |
|
|
0 commit comments