diff --git a/2-ui/1-document/07-modifying-document/article.md b/2-ui/1-document/07-modifying-document/article.md
index 86f5b4b2..9cdb79dd 100644
--- a/2-ui/1-document/07-modifying-document/article.md
+++ b/2-ui/1-document/07-modifying-document/article.md
@@ -4,11 +4,9 @@ DOM modifications is the key to create "live" pages.
Here we'll see how to create new elements "on the fly" and modify the existing page content.
-First we'll see a simple example and then explain the methods.
-
## Example: show a message
-For a start, let's see how to add a message on the page that looks nicer than `alert`.
+Let's see the methods on example. We'll add a message on the page that looks nicer than `alert`.
Here's how it will look:
@@ -30,11 +28,10 @@ Here's how it will look:
*/!*
```
-That was an HTML example. Now let's create the same `div` with JavaScript (assuming that the styles are still in the HTML or an external CSS file).
+That was an HTML example. Now let's create the same `div` with JavaScript (assuming that the styles are in the HTML or an external CSS file).
## Creating an element
-
To create DOM nodes, there are two methods:
`document.createElement(tag)`
@@ -53,21 +50,21 @@ To create DOM nodes, there are two methods:
### Creating the message
-In our case we want to make a `div` with given classes and the message in it:
+In our case the message is a `div` with `alert` class and the HTML in it:
```js
let div = document.createElement('div');
-div.className = "alert alert-success";
+div.className = "alert";
div.innerHTML = "Hi there! You've read an important message.";
```
-After that, we have our DOM element ready. Right now it is just in a variable and we cannot see it. That is because it's not yet inserted into the page.
+We created the element, but as of now it's only in a variable. We can't see the element on the page, as it's not yet a part of the document.
## Insertion methods
To make the `div` show up, we need to insert it somewhere into `document`. For instance, in `document.body`.
-There's a special method `appendChild` for that: `document.body.appendChild(div)`.
+There's a special method `append` for that: `document.body.append(div)`.
Here's the full code:
@@ -84,77 +81,16 @@ Here's the full code:
```
-Here's a brief list of methods to insert a node into a parent element (`parentElem` for short):
-
-`parentElem.appendChild(node)`
-: Appends `node` as the last child of `parentElem`.
-
- The following example adds a new `
` to the end of ``:
-
- ```html run height=100
-
- - 0
- - 1
- - 2
-
-
-
- ```
-
-`parentElem.insertBefore(node, nextSibling)`
-: Inserts `node` before `nextSibling` into `parentElem`.
-
- The following code inserts a new list item before the second `- `:
-
- ```html run height=100
-
- - 0
- - 1
- - 2
-
-
- ```
- To insert `newLi` as the first element, we can do it like this:
-
- ```js
- list.insertBefore(newLi, list.firstChild);
- ```
-
-`parentElem.replaceChild(node, oldChild)`
-: Replaces `oldChild` with `node` among children of `parentElem`.
-
-All these methods return the inserted node. In other words, `parentElem.appendChild(node)` returns `node`. But usually the returned value is not used, we just run the method.
-
-These methods are "old school": they exist from the ancient times and we can meet them in many old scripts. Unfortunately, they are not flexible enough.
-
-For instance, how to insert *html* if we have it as a string? Or, given a node, without reference to its parent, how to remove it? Of course, that's doable, but not in an elegant way.
-
-So there exist two other sets of insertion methods to handle all cases easily.
-
-### prepend/append/before/after
-
-This set of methods provides more flexible insertions:
+This set of methods provides more ways to insert:
- `node.append(...nodes or strings)` -- append nodes or strings at the end of `node`,
- `node.prepend(...nodes or strings)` -- insert nodes or strings into the beginning of `node`,
@@ -162,9 +98,7 @@ This set of methods provides more flexible insertions:
- `node.after(...nodes or strings)` –- insert nodes or strings after the `node`,
- `node.replaceWith(...nodes or strings)` –- replaces `node` with the given nodes or strings.
-All of them accept a list of DOM nodes and/or text strings. If a string is given it's inserted as a text node.
-
-Here's an example of using these methods to add more items to a list and the text before/after it:
+Here's an example of using these methods to add items to a list and the text before/after it:
```html autorun
@@ -174,20 +108,20 @@ Here's an example of using these methods to add more items to a list and the tex
```
-Here's a small picture what methods do:
+Here's a visual picture what methods do:

@@ -234,9 +168,9 @@ So, these methods can only be used to insert DOM nodes or text pieces.
But what if we want to insert HTML "as html", with all tags and stuff working, like `elem.innerHTML`?
-### insertAdjacentHTML/Text/Element
+## insertAdjacentHTML/Text/Element
-There's another, pretty versatile method: `elem.insertAdjacentHTML(where, html)`.
+For that we can use another, pretty versatile method: `elem.insertAdjacentHTML(where, html)`.
The first parameter is a code word, specifying where to insert relative to `elem`. Must be one of the following:
@@ -265,7 +199,7 @@ For instance:
Bye
```
-That's how we can append an arbitrary HTML to our page.
+That's how we can append an arbitrary HTML to the page.
Here's the picture of insertion variants:
@@ -294,12 +228,56 @@ So here's an alternative variant of showing a message:
```
+## Node removal
+
+To remove a node, there's a method `node.remove()`.
+
+Let's make our message disappear after a second:
+
+```html run untrusted
+
+
+
+```
+
+Please note: if we want to *move* an element to another place -- there's no need to remove it from the old one.
+
+**All insertion methods automatically remove the node from the old place.**
+
+For instance, let's swap elements:
+
+```html run height=50
+First
+Second
+
+```
+
## Cloning nodes: cloneNode
How to insert one more similar message?
@@ -337,7 +315,6 @@ An example of copying the message:
```
-
## DocumentFragment [#document-fragment]
`DocumentFragment` is a special DOM node that serves as a wrapper to pass around lists of nodes.
@@ -404,62 +381,84 @@ ul.append(...getListContent()); // append + "..." operator = friends!
We mention `DocumentFragment` mainly because there are some concepts on top of it, like [template](info:template-element) element, that we'll cover much later.
+## Old-school insert/remove methods
-## Removal methods
+[old]
-To remove nodes, there are the following methods:
+There are also "old school" DOM manipulation methods, existing for historical reasons.
+These methods come from really ancient times. Nowadays, there's no reason to use them, as modern methods, such as `append`, `prepend`, `before`, `after`, `remove`, `replaceWith`, are more flexible.
+
+The only reason we list these methods here is that you can find them in many old scripts:
+
+`parentElem.appendChild(node)`
+: Appends `node` as the last child of `parentElem`.
+
+ The following example adds a new ` - ` to the end of `
`:
+
+ ```html run height=100
+
+ - 0
+ - 1
+ - 2
+
+
+
+ ```
+
+`parentElem.insertBefore(node, nextSibling)`
+: Inserts `node` before `nextSibling` into `parentElem`.
+
+ The following code inserts a new list item before the second `- `:
+
+ ```html run height=100
+
+ - 0
+ - 1
+ - 2
+
+
+ ```
+ To insert `newLi` as the first element, we can do it like this:
+
+ ```js
+ list.insertBefore(newLi, list.firstChild);
+ ```
+
+`parentElem.replaceChild(node, oldChild)`
+: Replaces `oldChild` with `node` among children of `parentElem`.
`parentElem.removeChild(node)`
-: Removes `node` from `parentElem` (assuming it's a child).
+: Removes `node` from `parentElem` (assuming `node` is its child).
-`node.remove()`
-: Removes the `node` from its place.
+ The following example removes first ` - ` from `
`:
-We can easily see that the second method is much shorter. The first one exists for historical reasons.
+ ```html run height=100
+
+ - 0
+ - 1
+ - 2
+
-````smart
-If we want to *move* an element to another place -- there's no need to remove it from the old one.
+
+ ```
-**All insertion methods automatically remove the node from the old place.**
-
-For instance, let's swap elements:
-
-```html run height=50
-First
-Second
-
-```
-````
-
-Let's make our message disappear after a second:
-
-```html run untrusted
-
-
-
-```
+All these methods return the inserted/removed node. In other words, `parentElem.appendChild(node)` returns `node`. But usually the returned value is not used, we just run the method.
## A word about "document.write"
@@ -502,51 +501,48 @@ For instance:
So it's kind of unusable at "after loaded" stage, unlike other DOM methods we covered above.
-That was the downside.
+That's the downside.
-Technically, when `document.write` is called while the browser is reading ("parsing") incoming HTML, and it writes something, the browser consumes it just as if it were initially there, in the HTML text.
+There's an upside also. Technically, when `document.write` is called while the browser is reading ("parsing") incoming HTML, and it writes something, the browser consumes it just as if it were initially there, in the HTML text.
-That gives us the upside -- it works blazingly fast, because there's *no DOM modification*. It writes directly into the page text, while the DOM is not yet built, and the browser puts it into DOM at generation-time.
+So it works blazingly fast, because there's *no DOM modification* involved. It writes directly into the page text, while the DOM is not yet built.
So if we need to add a lot of text into HTML dynamically, and we're at page loading phase, and the speed matters, it may help. But in practice these requirements rarely come together. And usually we can see this method in scripts just because they are old.
## Summary
-Methods to create new nodes:
+- Methods to create new nodes:
+ - `document.createElement(tag)` -- creates an element with the given tag,
+ - `document.createTextNode(value)` -- creates a text node (rarely used),
+ - `elem.cloneNode(deep)` -- clones the element, if `deep==true` then with all descendants.
-- `document.createElement(tag)` -- creates an element with the given tag,
-- `document.createTextNode(value)` -- creates a text node (rarely used),
-- `elem.cloneNode(deep)` -- clones the element, if `deep==true` then with all descendants.
+- Insertion and removal:
+ - `node.append(...nodes or strings)` -- insert into `node`, at the end,
+ - `node.prepend(...nodes or strings)` -- insert into `node`, at the beginning,
+ - `node.before(...nodes or strings)` –- insert right before `node`,
+ - `node.after(...nodes or strings)` –- insert right after `node`,
+ - `node.replaceWith(...nodes or strings)` –- replace `node`.
+ - `node.remove()` –- remove the `node`.
-Insertion and removal of nodes:
+ Text strings are inserted "as text".
-- From the parent:
- - `parent.appendChild(node)`
- - `parent.insertBefore(node, nextSibling)`
- - `parent.removeChild(node)`
- - `parent.replaceChild(newElem, node)`
+- There are also "old school" methods:
+ - `parent.appendChild(node)`
+ - `parent.insertBefore(node, nextSibling)`
+ - `parent.removeChild(node)`
+ - `parent.replaceChild(newElem, node)`
- All these methods return `node`.
+ All these methods return `node`.
-- Given a list of nodes and strings:
- - `node.append(...nodes or strings)` -- insert into `node`, at the end,
- - `node.prepend(...nodes or strings)` -- insert into `node`, at the beginning,
- - `node.before(...nodes or strings)` –- insert right before `node`,
- - `node.after(...nodes or strings)` –- insert right after `node`,
- - `node.replaceWith(...nodes or strings)` –- replace `node`.
- - `node.remove()` –- remove the `node`.
+- Given a piece of HTML: `elem.insertAdjacentHTML(where, html)`, inserts depending on `where`:
+ - `"beforebegin"` -- insert `html` right before `elem`,
+ - `"afterbegin"` -- insert `html` into `elem`, at the beginning,
+ - `"beforeend"` -- insert `html` into `elem`, at the end,
+ - `"afterend"` -- insert `html` right after `elem`.
- Text strings are inserted "as text".
-
-- Given a piece of HTML: `elem.insertAdjacentHTML(where, html)`, inserts depending on where:
- - `"beforebegin"` -- insert `html` right before `elem`,
- - `"afterbegin"` -- insert `html` into `elem`, at the beginning,
- - `"beforeend"` -- insert `html` into `elem`, at the end,
- - `"afterend"` -- insert `html` right after `elem`.
-
- Also there are similar methods `elem.insertAdjacentText` and `elem.insertAdjacentElement`, they insert text strings and elements, but they are rarely used.
+ Also there are similar methods `elem.insertAdjacentText` and `elem.insertAdjacentElement`, they insert text strings and elements, but they are rarely used.
- To append HTML to the page before it has finished loading:
- - `document.write(html)`
+ - `document.write(html)`
- After the page is loaded such a call erases the document. Mostly seen in old scripts.
+ After the page is loaded such a call erases the document. Mostly seen in old scripts.
diff --git a/2-ui/1-document/07-modifying-document/before-prepend-append-after.svg b/2-ui/1-document/07-modifying-document/before-prepend-append-after.svg
index 11d7e0e2..38531c6f 100644
--- a/2-ui/1-document/07-modifying-document/before-prepend-append-after.svg
+++ b/2-ui/1-document/07-modifying-document/before-prepend-append-after.svg
@@ -62,8 +62,8 @@
ol.before
-
- ol.*(…nodes or strings)
+
+ (…nodes or strings)
diff --git a/2-ui/1-document/09-size-and-scroll/metric-offset-width-height.svg b/2-ui/1-document/09-size-and-scroll/metric-offset-width-height.svg
index 1a2384a1..64878693 100644
--- a/2-ui/1-document/09-size-and-scroll/metric-offset-width-height.svg
+++ b/2-ui/1-document/09-size-and-scroll/metric-offset-width-height.svg
@@ -15,9 +15,9 @@
-
-
-
+
+
+
@@ -40,72 +40,72 @@
- border
- 25px
+ border
+ 25px
- padding
- 20px
+ padding
+ 20px
- content width:
- 284px
+ content width:
+ 284px
-
- height:
- 200px
+
+ height:
+ 200px
-
-
-
-
-
-
+
+
+
+
+
+
- border
- 25px
+ border
+ 25px
- padding
- 20px
+ padding
+ 20px
- scrollbar
- 16px
+ scrollbar
+ 16px
-
-
-
-
-
+
+
+
+
+
- offsetWidth =
- 25+20+284+20+16+25
- =
- 390px
+ offsetWidth =
+ 25+20+284+20+16+25
+ =
+ 390px
-
-
-
-
- offsetHeight:
- 290px
+
+
+
+
+ offsetHeight:
+ 290px
-
-
-
+
+
+
- Introduction
-
- This Ecma Standard is based on several
- originating technologies, the most well
- known being JavaScript (Netscape) and
- JScript (Microsoft). The language was
- invented by Brendan Eich at Netscape and
- first appeared in that company’s Navigator
- 2.0 browser. It has appeared in all
- subsequent browsers from Netscape and
- in all browsers from Microsoft starting with
+ Introduction
+
+ This Ecma Standard is based on several
+ originating technologies, the most well
+ known being JavaScript (Netscape) and
+ JScript (Microsoft). The language was
+ invented by Brendan Eich at Netscape and
+ first appeared in that company’s Navigator
+ 2.0 browser. It has appeared in all
+ subsequent browsers from Netscape and
+ in all browsers from Microsoft starting with
diff --git a/figures.sketch b/figures.sketch
index 7034ba31..462635b8 100644
Binary files a/figures.sketch and b/figures.sketch differ