@@ -84,7 +84,7 @@ let divs = document.getElementsByTagName('div');
84
84
85
85
This method is callable in the context of any DOM element.
86
86
87
- Let's find all ` input ` inside the table:
87
+ Let's find all ` input ` tags inside the table:
88
88
89
89
``` html run height=50
90
90
<table id =" table" >
@@ -123,16 +123,16 @@ The `"s"` letter is absent in `getElementById`, because it returns a single elem
123
123
```
124
124
125
125
````warn header="It returns a collection, not an element!"
126
- Another widespread novice mistake is to write like :
126
+ Another widespread novice mistake is to write:
127
127
128
128
```js
129
129
// doesn't work
130
130
document.getElementsByTagName('input').value = 5;
131
131
```
132
132
133
- That won't work, because it takes a * collection* of inputs and assigns the value to it, rather to elements inside it.
133
+ That won't work, because it takes a * collection* of inputs and assigns the value to it rather than to elements inside it.
134
134
135
- We should either iterate over the collection or get an element by the number , and then assign, like this:
135
+ We should either iterate over the collection or get an element by its index , and then assign, like this:
136
136
137
137
``` js
138
138
// should work (if there's an input)
@@ -374,7 +374,7 @@ Other methods can be called on elements too. For instance `elem.querySelectorAll
374
374
Besides that:
375
375
376
376
- There is `elem.matches(css)` to check if `elem` matches the given CSS selector.
377
- - There is `elem.closest(css)` to look for a nearest ancestor that matches the given CSS-selector. The `elem` itself is also checked.
377
+ - There is `elem.closest(css)` to look for the nearest ancestor that matches the given CSS-selector. The `elem` itself is also checked.
378
378
379
379
And let's mention one more method here to check for the child-parent relationship:
380
380
- `elemA.contains(elemB)` returns true if `elemB` is inside `elemA` (a descendant of `elemA`) or when `elemA==elemB`.
0 commit comments