Skip to content

DOM navigation #328

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 13 commits into from
Apr 27, 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
16 changes: 8 additions & 8 deletions 2-ui/1-document/03-dom-navigation/1-dom-children/solution.md
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
There are many ways, for instance:
Існує багато способів, наприклад:


The `<div>` DOM node:
До DOM вузла `<div>`:

```js
document.body.firstElementChild
// or
// або
document.body.children[0]
// or (the first node is space, so we take 2nd)
// або (перший вузол -- це пробіл, тому беремо 2-й)
document.body.childNodes[1]
```

The `<ul>` DOM node:
До DOM вузла `<ul>`:

```js
document.body.lastElementChild
// or
// або
document.body.children[1]
```

The second `<li>` (with Pete):
До другого `<li>` (Петро):

```js
// get <ul>, and then get its last element child
// отримати <ul>, а потім отримати його останній дочірній елемент
document.body.lastElementChild.lastElementChild
```
18 changes: 9 additions & 9 deletions 2-ui/1-document/03-dom-navigation/1-dom-children/task.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,23 @@ importance: 5

---

# DOM children
# Діти у DOM

Look at this page:
Подивіться на цю сторінку:

```html
<html>
<body>
<div>Users:</div>
<div>Користувачи:</div>
<ul>
<li>John</li>
<li>Pete</li>
<li>Іван</li>
<li>Петро</li>
</ul>
</body>
</html>
```

For each of the following, give at least one way of how to access them:
- The `<div>` DOM node?
- The `<ul>` DOM node?
- The second `<li>` (with Pete)?
Вкажіть принаймні один спосіб доступу до кожного з перелічених нижче DOM вузлів:
- До DOM вузла `<div>`?
- До DOM вузла `<ul>`?
- До другого `<li>` (Петро)?
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
1. Yes, true. The element `elem.lastChild` is always the last one, it has no `nextSibling`.
2. No, wrong, because `elem.children[0]` is the first child *among elements*. But there may exist non-element nodes before it. So `previousSibling` may be a text node.
1. Так, це правда. Елемент `elem.lastChild` завжди останній, у нього немає `nextSibling`.
2. Ні, це неправда, тому що `elem.children[0]` — перший дочірній *серед елементів*. Але перед ним можуть існувати вузли інших типів. Отже, `previousSibling` може бути, наприклад, текстовим вузлом.

Please note: for both cases if there are no children, then there will be an error.
Зверніть увагу: в обох випадках якщо немає дітей, то буде помилка.

If there are no children, `elem.lastChild` is `null`, so we can't access `elem.lastChild.nextSibling`. And the collection `elem.children` is empty (like an empty array `[]`).
Якщо дочірніх елементів немає, `elem.lastChild` матиме значення `null`, тому ми не зможемо отримати доступ до `elem.lastChild.nextSibling`. А колекція `elem.children` порожня (як порожній масив `[]`).
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ importance: 5

---

# The sibling question
# Питання про сусідів

If `elem` -- is an arbitrary DOM element node...
Якщо `elem` -- це довільний DOM елемент...

- Is it true that `elem.lastChild.nextSibling` is always `null`?
- Is it true that `elem.children[0].previousSibling` is always `null` ?
- Чи правда що `elem.lastChild.nextSibling` завжди `null`?
- Чи правда що `elem.children[0].previousSibling` завжди `null`?
Original file line number Diff line number Diff line change
@@ -1 +1 @@
We'll be using `rows` and `cells` properties to access diagonal table cells.
Ми будемо використовувати властивості `rows` та `cells` для доступу до діагональних клітинок таблиці.
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@ importance: 5

---

# Select all diagonal cells
# Виділіть усі діагональні клітинки

Write the code to paint all diagonal table cells in red.
Напишіть код, щоб зафарбувати всі діагональні клітинки таблиці червоним кольором.

You'll need to get all diagonal `<td>` from the `<table>` and paint them using the code:
Вам потрібно буде отримати всі діагоналі `<td>` з `<table>` і розфарбувати їх за допомогою коду:

```js
// td should be the reference to the table cell
// у td має бути посилання на клітинку таблиці
td.style.backgroundColor = 'red';
```

The result should be:
Результат повинен бути таким:

[iframe src="solution" height=180]
Loading