Skip to content

Searching: getElement*, querySelector* #246

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,35 +1,35 @@
There are many ways to do it.
Є багато способів зробити це.

Here are some of them:
Ось деякі з них:

```js
// 1. The table with `id="age-table"`.
// 1. Таблиця з `id="age-table"`.
let table = document.getElementById('age-table')

// 2. All label elements inside that table
// 2. Всі елементи label всередині цієї таблиці
table.getElementsByTagName('label')
// or
// або
document.querySelectorAll('#age-table label')

// 3. The first td in that table (with the word "Age")
// 3. Перший td в цій таблиці (зі словом "Age")
table.rows[0].cells[0]
// or
// або
table.getElementsByTagName('td')[0]
// or
// або
table.querySelector('td')

// 4. The form with the name "search"
// assuming there's only one element with name="search" in the document
// 4. форма з іменем "search"
// припускаємо, що в документі є лише один елемент з name="search".
let form = document.getElementsByName('search')[0]
// or, form specifically
// або безпосередньо форма
document.querySelector('form[name="search"]')

// 5. The first input in that form.
// 5. Перший input у цій формі.
form.getElementsByTagName('input')[0]
// or
// або
form.querySelector('input')

// 6. The last input in that form
let inputs = form.querySelectorAll('input') // find all inputs
inputs[inputs.length-1] // take the last one
// 6. Останній input у цій формі
let inputs = form.querySelectorAll('input') // знайти всі input
inputs[inputs.length-1] // взяти останній
```
20 changes: 10 additions & 10 deletions 2-ui/1-document/04-searching-elements-dom/1-find-elements/task.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@ importance: 4

---

# Search for elements
# Пошук елементів

Here's the document with the table and form.
Ось документ із таблицею та формою.

How to find?...
Як знайти?...

1. The table with `id="age-table"`.
2. All `label` elements inside that table (there should be 3 of them).
3. The first `td` in that table (with the word "Age").
4. The `form` with `name="search"`.
5. The first `input` in that form.
6. The last `input` in that form.
1. Таблиця з `id="age-table"`.
2. Усі елементи `label` всередині цієї таблиці (їх має бути 3).
3. Перший `td` у цій таблиці (зі словом "Age").
4. `form` з `name="search"`.
5. Перший `input` у цій формі.
6. Останній `input` у цій формі.

Open the page [table.html](table.html) in a separate window and make use of browser tools for that.
Відкрийте сторінку [table.html](table.html) в окремому вікні та скористайтеся для цього інструментами браузера.
Loading