diff --git a/2-ui/1-document/05-basic-dom-node-properties/2-tree-info/solution.md b/2-ui/1-document/05-basic-dom-node-properties/2-tree-info/solution.md
index 781b7a929..0088882c2 100644
--- a/2-ui/1-document/05-basic-dom-node-properties/2-tree-info/solution.md
+++ b/2-ui/1-document/05-basic-dom-node-properties/2-tree-info/solution.md
@@ -6,7 +6,9 @@ for (let li of document.querySelectorAll('li')) {
}
```
-In the loop we need to get the text inside every `li`. We can read it directly from the first child node, that is the text node:
+In the loop we need to get the text inside every `li`.
+
+We can read the text from the first child node of `li`, that is the text node:
```js
for (let li of document.querySelectorAll('li')) {
@@ -16,4 +18,4 @@ for (let li of document.querySelectorAll('li')) {
}
```
-Then we can get the number of descendants `li.getElementsByTagName('li')`.
+Then we can get the number of descendants as `li.getElementsByTagName('li').length`.
diff --git a/2-ui/1-document/05-basic-dom-node-properties/4-where-document-in-hierarchy/solution.md b/2-ui/1-document/05-basic-dom-node-properties/4-where-document-in-hierarchy/solution.md
index db7ebc9d8..cb9456717 100644
--- a/2-ui/1-document/05-basic-dom-node-properties/4-where-document-in-hierarchy/solution.md
+++ b/2-ui/1-document/05-basic-dom-node-properties/4-where-document-in-hierarchy/solution.md
@@ -27,7 +27,7 @@ Also, there's a reference to the constructor function inside the `prototype`:
alert(HTMLDocument.prototype.constructor === HTMLDocument); // true
```
-For built-in classes in all prototypes there's a `constructor` reference, and we can get `constructor.name` to see the name of the class. Let's do it for all objects in the `document` prototype chain:
+To get a name of the class as a string, we can use `constructor.name`. Let's do it for the whole `document` prototype chain, till class `Node`:
```js run
alert(HTMLDocument.prototype.constructor.name); // HTMLDocument
@@ -35,4 +35,6 @@ alert(HTMLDocument.prototype.__proto__.constructor.name); // Document
alert(HTMLDocument.prototype.__proto__.__proto__.constructor.name); // Node
```
+That's the hierarchy.
+
We also could examine the object using `console.dir(document)` and see these names by opening `__proto__`. The console takes them from `constructor` internally.
diff --git a/2-ui/1-document/05-basic-dom-node-properties/article.md b/2-ui/1-document/05-basic-dom-node-properties/article.md
index 4b122d03e..99dde5bcd 100644
--- a/2-ui/1-document/05-basic-dom-node-properties/article.md
+++ b/2-ui/1-document/05-basic-dom-node-properties/article.md
@@ -2,15 +2,15 @@
Let's get a more in-depth look at DOM nodes.
-In this chapter we'll see more into what they are and their most used properties.
+In this chapter we'll see more into what they are and learn their most used properties.
## DOM node classes
-DOM nodes have different properties depending on their class. For instance, an element node corresponding to tag `` has link-related properties, and the one corresponding to `` has input-related properties and so on. Text nodes are not the same as element nodes. But there are also common properties and methods between all of them, because all classes of DOM nodes form a single hierarchy.
+Different DOM nodes may have different properties. For instance, an element node corresponding to tag `` has link-related properties, and the one corresponding to `` has input-related properties and so on. Text nodes are not the same as element nodes. But there are also common properties and methods between all of them, because all classes of DOM nodes form a single hierarchy.
Each DOM node belongs to the corresponding built-in class.
-The root of the hierarchy is [EventTarget](https://dom.spec.whatwg.org/#eventtarget), that is inherited by [Node](http://dom.spec.whatwg.org/#interface-node), and other DOM nodes inherit from it.
+The root of the hierarchy is [EventTarget](https://dom.spec.whatwg.org/#eventtarget), that is inherited by [Node](https://dom.spec.whatwg.org/#interface-node), and other DOM nodes inherit from it.
Here's the picture, explanations to follow:
@@ -18,10 +18,31 @@ Here's the picture, explanations to follow:
The classes are:
-- [EventTarget](https://dom.spec.whatwg.org/#eventtarget) -- is the root "abstract" class. Objects of that class are never created. It serves as a base, so that all DOM nodes support so-called "events", we'll study them later.
-- [Node](http://dom.spec.whatwg.org/#interface-node) -- is also an "abstract" class, serving as a base for DOM nodes. It provides the core tree functionality: `parentNode`, `nextSibling`, `childNodes` and so on (they are getters). Objects of `Node` class are never created. But there are concrete node classes that inherit from it, namely: `Text` for text nodes, `Element` for element nodes and more exotic ones like `Comment` for comment nodes.
-- [Element](http://dom.spec.whatwg.org/#interface-element) -- is a base class for DOM elements. It provides element-level navigation like `nextElementSibling`, `children` and searching methods like `getElementsByTagName`, `querySelector`. A browser supports not only HTML, but also XML and SVG. The `Element` class serves as a base for more specific classes: `SVGElement`, `XMLElement` and `HTMLElement`.
-- [HTMLElement](https://html.spec.whatwg.org/multipage/dom.html#htmlelement) -- is finally the basic class for all HTML elements. It is inherited by concrete HTML elements:
+- [EventTarget](https://dom.spec.whatwg.org/#eventtarget) -- is the root "abstract" class for everything.
+
+ Objects of that class are never created. It serves as a base, so that all DOM nodes support so-called "events", we'll study them later.
+
+- [Node](https://dom.spec.whatwg.org/#interface-node) -- is also an "abstract" class, serving as a base for DOM nodes.
+
+ It provides the core tree functionality: `parentNode`, `nextSibling`, `childNodes` and so on (they are getters). Objects of `Node` class are never created. But there are other classes that inherit from it (and so inherit the `Node` functionality).
+
+- [Document](https://dom.spec.whatwg.org/#interface-document), for historical reasons often inherited by `HTMLDocument` (though the latest spec doesn't dictate it) -- is a document as a whole.
+
+ The `document` global object belongs exactly to this class. It serves as an entry point to the DOM.
+
+- [CharacterData](https://dom.spec.whatwg.org/#interface-characterdata) -- an "abstract" class, inherited by:
+ - [Text](https://dom.spec.whatwg.org/#interface-text) -- the class corresponding to a text inside elements, e.g. `Hello` in `Hello
`.
+ - [Comment](https://dom.spec.whatwg.org/#interface-comment) -- the class for comments. They are not shown, but each comment becomes a member of DOM.
+
+- [Element](https://dom.spec.whatwg.org/#interface-element) -- is the base class for DOM elements.
+
+ It provides element-level navigation like `nextElementSibling`, `children` and searching methods like `getElementsByTagName`, `querySelector`.
+
+ A browser supports not only HTML, but also XML and SVG. So the `Element` class serves as a base for more specific classes: `SVGElement`, `XMLElement` (we don't need them here) and `HTMLElement`.
+
+- Finally, [HTMLElement](https://html.spec.whatwg.org/multipage/dom.html#htmlelement) is the basic class for all HTML elements. We'll work with it most of the time.
+
+ It is inherited by concrete HTML elements:
- [HTMLInputElement](https://html.spec.whatwg.org/multipage/forms.html#htmlinputelement) -- the class for `` elements,
- [HTMLBodyElement](https://html.spec.whatwg.org/multipage/semantics.html#htmlbodyelement) -- the class for `` elements,
- [HTMLAnchorElement](https://html.spec.whatwg.org/multipage/semantics.html#htmlanchorelement) -- the class for `` elements,
@@ -29,9 +50,9 @@ The classes are:
There are many other tags with their own classes that may have specific properties and methods, while some elements, such as ``, ``, `` do not have any specific properties, so they are instances of `HTMLElement` class.
-So, the full set of properties and methods of a given node comes as the result of the inheritance.
+So, the full set of properties and methods of a given node comes as the result of the chain of inheritance.
-For example, let's consider the DOM object for an `` element. It belongs to [HTMLInputElement](https://html.spec.whatwg.org/multipage/forms.html#htmlinputelement) class. It gets properties and methods as a superposition of:
+For example, let's consider the DOM object for an `` element. It belongs to [HTMLInputElement](https://html.spec.whatwg.org/multipage/forms.html#htmlinputelement) class.
It gets properties and methods as a superposition of (listed in inheritance order):
@@ -40,9 +61,9 @@ It gets properties and methods as a superposition of (listed in inheritance orde
- `Element` -- provides generic element methods,
- `Node` -- provides common DOM node properties,
- `EventTarget` -- gives the support for events (to be covered),
-- ...and finally it inherits from `Object`, so "pure object" methods like `hasOwnProperty` are also available.
+- ...and finally it inherits from `Object`, so "plain object" methods like `hasOwnProperty` are also available.
-To see the DOM node class name, we can recall that an object usually has the `constructor` property. It references to the class constructor, and `constructor.name` is its name:
+To see the DOM node class name, we can recall that an object usually has the `constructor` property. It references the class constructor, and `constructor.name` is its name:
```js run
alert( document.body.constructor.name ); // HTMLBodyElement
@@ -80,7 +101,7 @@ Try it on `document.body`.
```
````smart header="IDL in the spec"
-In the specification, classes are described not using JavaScript, but a special [Interface description language](https://en.wikipedia.org/wiki/Interface_description_language) (IDL), that is usually easy to understand.
+In the specification, DOM classes aren't described by using JavaScript, but a special [Interface description language](https://en.wikipedia.org/wiki/Interface_description_language) (IDL), that is usually easy to understand.
In IDL all properties are prepended with their types. For instance, `DOMString`, `boolean` and so on.
@@ -95,7 +116,7 @@ interface HTMLInputElement: HTMLElement {
// here go properties and methods of elements
*!*
- // "DOMString" means that the value of these properties are strings
+ // "DOMString" means that the value of a property is a string
*/!*
attribute DOMString accept;
attribute DOMString alt;
@@ -114,13 +135,11 @@ interface HTMLInputElement: HTMLElement {
...
}
```
-
-Other classes are somewhat similar.
````
## The "nodeType" property
-The `nodeType` property provides an old-fashioned way to get the "type" of a DOM node.
+The `nodeType` property provides one more, "old-fashioned" way to get the "type" of a DOM node.
It has a numeric value:
- `elem.nodeType == 1` for element nodes,
@@ -135,10 +154,10 @@ For instance:
```
-If we only deal with elements, then `tagName` is the only thing we should use.
-
+If we only deal with elements, then we can use both `tagName` and `nodeName` - there's no difference.
```smart header="The tag name is always uppercase except in XML mode"
The browser has two modes of processing documents: HTML and XML. Usually the HTML-mode is used for webpages. XML-mode is enabled when the browser receives an XML-document with the header: `Content-Type: application/xml+xhtml`.
@@ -205,7 +223,7 @@ In XML mode the case is kept "as is". Nowadays XML mode is rarely used.
The [innerHTML](https://w3c.github.io/DOM-Parsing/#the-innerhtml-mixin) property allows to get the HTML inside the element as a string.
-We can also modify it. So it's one of most powerful ways to change the page.
+We can also modify it. So it's one of the most powerful ways to change the page.
The example shows the contents of `document.body` and then replaces it completely:
@@ -236,14 +254,12 @@ We can try to insert invalid HTML, the browser will fix our errors:
```
```smart header="Scripts don't execute"
-If `innerHTML` inserts a `
```
@@ -326,7 +342,7 @@ So what happened in `div.outerHTML=...` is:
- Another piece of HTML `A new element
` was inserted in its place.
- `div` still has its old value. The new HTML wasn't saved to any variable.
-That's possible with `innerHTML`, but not with `outerHTML`.
+It's so easy to make an error here: modify `div.outerHTML` and then continue to work with `div` as if it had the new content in it. But it doesn't. Such thing is correct for `innerHTML`, but not for `outerHTML`.
We can write to `elem.outerHTML`, but should keep in mind that it doesn't change the element we're writing to ('elem'). It puts the new HTML in its place instead. We can get references to the new elements by querying the DOM.
@@ -334,9 +350,9 @@ We can write to `elem.outerHTML`, but should keep in mind that it doesn't change
The `innerHTML` property is only valid for element nodes.
-Other node types have their counterpart: `nodeValue` and `data` properties. These two are almost the same for practical use, there are only minor specification differences. So we'll use `data`, because it's shorter.
+Other node types, such as text nodes, have their counterpart: `nodeValue` and `data` properties. These two are almost the same for practical use, there are only minor specification differences. So we'll use `data`, because it's shorter.
-We can read it, like this:
+An example of reading the content of a text node and a comment:
```html run height="50"
@@ -356,7 +372,9 @@ We can read it, like this:
```
-For text nodes we can imagine a reason to read or modify them, but why comments? Usually, they are not interesting at all, but sometimes developers embed information into HTML in them, like this:
+For text nodes we can imagine a reason to read or modify them, but why comments?
+
+Sometimes developers embed information or template instructions into HTML in them, like this:
```html
@@ -364,7 +382,7 @@ For text nodes we can imagine a reason to read or modify them, but why comments?
```
-...Then JavaScript can read it and process embedded instructions.
+...Then JavaScript can read it from `data` property and process embedded instructions.
## textContent: pure text
@@ -447,7 +465,7 @@ Here's a blinking element:
## More properties
-DOM elements also have additional properties, many of them provided by the class:
+DOM elements also have additional properties, in particular those that depend on the class:
- `value` -- the value for ``, `