This commit is contained in:
Ilya Kantor 2017-03-13 00:21:00 +03:00
parent 8360ebbe90
commit dbf5c7587c
31 changed files with 635 additions and 455 deletions

View file

@ -1,5 +1,5 @@
First, let's see how not to do it:
First, let's see how *not* to do it:
```js
function clear(elem) {
@ -9,11 +9,11 @@ function clear(elem) {
}
```
That won't work, because the call to `remove()` shifts the collection `elem.childNodes` every time, so elements every time start from index `0`. So `i` should not increase in the loop at all.
That won't work, because the call to `remove()` shifts the collection `elem.childNodes`, so elements start from the index `0` every time. But `i` increases, and some elements will be skipped.
The `for..of` loop also does the same.
The right variant would be:
The right variant could be:
```js
function clear(elem) {
@ -23,7 +23,7 @@ function clear(elem) {
}
```
And also there's a simpler variant:
And also there's a simpler way to do the same:
```js
function clear(elem) {

View file

@ -2,11 +2,11 @@ importance: 5
---
# clear
# Clear the element
Create a function `clear(elem)` that removes everything from element.
Create a function `clear(elem)` that removes everything from the element.
```html run
```html run height=60
<ol id="elem">
<li>Hello</li>
<li>World</li>