`. На даний момент його довжина дорівнює `1`.
+2. Другий скрипт запускається після того, як браузер зустріне ще один `
`, тому його довжина дорівнює `2`.
```html run
-
First div
+
Перший div
-
Second div
+
Другий div
```
-In contrast, `querySelectorAll` returns a *static* collection. It's like a fixed array of elements.
+На відміну від цього, `querySelectorAll` повертає *статичну* колекцію. Це схоже на фіксований масив елементів.
-If we use it instead, then both scripts output `1`:
+Якщо ми використаємо його у вищенаведеному прикладі, тоді обидва сценарії виведуть `1`:
```html run
-
First div
+
Перший div
-
Second div
+
Другий div
```
-Now we can easily see the difference. The static collection did not increase after the appearance of a new `div` in the document.
+Тепер ми легко бачимо різницю. Статична колекція не збільшилася після появи нового `div` у документі.
-## Summary
+## Підсумки
-There are 6 main methods to search for nodes in DOM:
+Існує 6 основних методів пошуку елементів у DOM:
-Method |
-Searches by... |
-Can call on an element? |
-Live? |
+Метод |
+Шукає, використовуючи... |
+Чи може викликатися на елементі? |
+Чи повертає живу колекцію? |
querySelector |
-CSS-selector |
+CSS-селектор |
✔ |
- |
querySelectorAll |
-CSS-selector |
+CSS-селектор |
✔ |
- |
@@ -344,31 +344,31 @@ There are 6 main methods to search for nodes in DOM:
getElementsByName |
-name |
+ім’я |
- |
✔ |
getElementsByTagName |
-tag or '*' |
+тег або '*' |
✔ |
✔ |
getElementsByClassName |
-class |
+клас |
✔ |
✔ |
-By far the most used are `querySelector` and `querySelectorAll`, but `getElement(s)By*` can be sporadically helpful or found in the old scripts.
+Найчастіше використовуються `querySelector` і `querySelectorAll`, але `getElement(s)By*` може бути корисним час від часу або знаходитися в старому коді.
-Besides that:
+Крім того:
-- There is `elem.matches(css)` to check if `elem` matches the given CSS selector.
-- There is `elem.closest(css)` to look for the nearest ancestor that matches the given CSS-selector. The `elem` itself is also checked.
+- `elem.matches(css)` існує для того, щоб перевірити, чи відповідає `elem` заданому CSS-селектору.
+- `elem.closest(css)` існує для того, щоб шукати найближчого предка, який відповідає заданому CSS-селектору. Сам `elem` також перевіряється.
-And let's mention one more method here to check for the child-parent relationship, as it's sometimes useful:
-- `elemA.contains(elemB)` returns true if `elemB` is inside `elemA` (a descendant of `elemA`) or when `elemA==elemB`.
+І згадаймо тут ще один метод перевірки взаємовідносин нащадок-предок, оскільки він іноді стає в нагоді:
+- `elemA.contains(elemB)` повертає true, якщо `elemB` знаходиться всередині `elemA` (нащадок `elemA`) або коли `elemA==elemB`.
\ No newline at end of file