Skip to content

Walking the DOM #279

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 3 commits into from
May 16, 2023
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
29 changes: 14 additions & 15 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,26 @@
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)
document.body.childNodes[1]
document.body.firstElementChild;
// أو
document.body.children[0];
// أو (العقدة الأولى هي المسافة، لذلك نأخذ الثانية)
document.body.childNodes[1];
```

The `<ul>` DOM node:
عقدة `<DOM <ul`:

```js
document.body.lastElementChild
// or
document.body.children[1]
document.body.lastElementChild;
// أو
document.body.children[1];
```

The second `<li>` (with Pete):
العنصر `<li>` الثاني (مع Pete):

```js
// get <ul>, and then get its last element child
document.body.lastElementChild.lastElementChild
// احصل على <ul>، ثم احصل على آخر عنصر فرعي له
document.body.lastElementChild.lastElementChild;
```
27 changes: 14 additions & 13 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,24 @@ importance: 5

---

# DOM children
# اطفال ال DOM

Look at this page:
انظر إلى هذه الصفحة:

```html
<html>
<body>
<div>Users:</div>
<ul>
<li>John</li>
<li>Pete</li>
</ul>
</body>
<body>
<div>المستخدمون:</div>
<ul>
<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 <div`؟
- عقدة `<DOM <ul`؟
- العنصر `<li>` الثاني (مع Pete)؟
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