Skip to content

Translated 02-dom-nodes/task.md #10

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
Mar 8, 2020
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
15 changes: 7 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,26 @@
There are many ways, for instance:
ਇੱਥੇ ਬਹੁਤ ਸਾਰੇ ਤਰੀਕੇ ਹਨ, ਉਦਾਹਰਣ ਵਜੋਂ:


The `<div>` DOM node:
`<div>` DOM ਨੋਡ:

```js
document.body.firstElementChild
// or
// ਜਾਂ
document.body.children[0]
// or (the first node is space, so we take 2nd)
// ਜਾਂ (ਪਹਿਲਾ ਨੋਡ ਸਪੇਸ ਹੈ, ਇਸਲਈ ਅਸੀਂ ਦੂਜਾ ਸਥਾਨ ਲੈਂਦੇ ਹਾਂ)
document.body.childNodes[1]
```

The `<ul>` DOM node:
`<ul>`DOM ਨੋਡ:

```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
```
12 changes: 6 additions & 6 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,9 +2,9 @@ importance: 5

---

# DOM children
# DOM ਬੱਚੇ

Look at this page:
ਇਸ ਪੇਜ ਨੂੰ ਵੇਖੋ:

```html
<html>
Expand All @@ -18,7 +18,7 @@ Look at this page:
</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)?
ਹੇਠ ਲਿਖਿਆਂ ਵਿੱਚੋਂ ਹਰੇਕ ਲਈ, ਉਹਨਾਂ ਤੱਕ ਪਹੁੰਚਣ ਦੇ ਤਰੀਕੇ ਦਾ ਘੱਟੋ ਘੱਟ ਇੱਕ ਢੰਗ ਦਿਓ:
- `<div>`DOM ਨੋਡ?
- `<ul>` DOM ਨੋਡ?
- ਦੂਜਾ `<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]` ਪਹਿਲਾ ਬੱਚਾ ਹੈ *among elements*. ਪਰ ਇਸ ਤੋਂ ਪਹਿਲਾਂ ਗੈਰ-ਏਲੇਮੈਂਟ ਨੋਡ ਮੌਜੂਦ ਹੋ ਸਕਦੇ ਹਨ. ਇਸ ਲਈ`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...
If `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` ?