Skip to content

Commit b1f87b3

Browse files
authored
Merge pull request #185 from HachemiH/master
Node properties: type, tag and contents
2 parents 2f8ac87 + c4487db commit b1f87b3

File tree

9 files changed

+206
-206
lines changed

9 files changed

+206
-206
lines changed

2-ui/1-document/05-basic-dom-node-properties/2-lastchild-nodetype-inline/solution.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
There's a catch here.
1+
Il y a un piège ici.
22

3-
At the time of `<script>` execution the last DOM node is exactly `<script>`, because the browser did not process the rest of the page yet.
3+
Au moment de l'exécution de `<script>`, le dernier nœud DOM est exactement `<script>`, car le navigateur n'a pas encore traité le reste de la page.
44

5-
So the result is `1` (element node).
5+
Le résultat est donc `1` (nœud élément).
66

77
```html run height=60
88
<html>

2-ui/1-document/05-basic-dom-node-properties/2-lastchild-nodetype-inline/task.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ importance: 5
22

33
---
44

5-
# What's in the nodeType?
5+
# Qu'y a-t-il dans le nodeType ?
66

7-
What does the script show?
7+
Qu'affiche le script ?
88

99
```html
1010
<html>
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
1-
Let's make a loop over `<li>`:
1+
Faisons une boucle dans le `<li>`:
22

33
```js
44
for (let li of document.querySelectorAll('li')) {
55
...
66
}
77
```
88

9-
In the loop we need to get the text inside every `li`.
9+
Dans la boucle, nous devons obtenir le texte à l'intérieur de chaque `li`.
1010

11-
We can read the text from the first child node of `li`, that is the text node:
11+
Nous pouvons lire le texte du premier nœud enfant de `li`, c'est-à-dire le nœud texte :
1212

1313
```js
1414
for (let li of document.querySelectorAll('li')) {
1515
let title = li.firstChild.data;
1616

17-
// title is the text in <li> before any other nodes
17+
// title est le texte dans <li> avant tout autre noeud
1818
}
1919
```
2020

21-
Then we can get the number of descendants as `li.getElementsByTagName('li').length`.
21+
Ensuite, nous pouvons obtenir le nombre de descendants comme `li.getElementsByTagName('li').length`.

2-ui/1-document/05-basic-dom-node-properties/2-tree-info/task.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@ importance: 5
22

33
---
44

5-
# Count descendants
5+
# Compter les descendants
66

7-
There's a tree structured as nested `ul/li`.
7+
Il y a un arbre structuré comme un `ul/li` imbriqué.
88

9-
Write the code that for each `<li>` shows:
9+
Écrivez le code qui pour que chaque `<li>` affiche :
1010

11-
1. What's the text inside it (without the subtree)
12-
2. The number of nested `<li>` -- all descendants, including the deeply nested ones.
11+
1. Quel est le texte à l'intérieur (sans le sous-arbre)
12+
2. Le nombre de `<li>` imbriqués - tous les descendants, y compris ceux profondément imbriqués.
1313

1414
[demo src="solution"]
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
The answer: **`BODY`**.
1+
La réponse : **`BODY`**.
22

33
```html run
44
<script>
@@ -10,8 +10,8 @@ The answer: **`BODY`**.
1010
</script>
1111
```
1212

13-
What's going on step by step:
13+
Ce qui se passe pas à pas :
1414

15-
1. The content of `<body>` is replaced with the comment. The comment is `<!--BODY-->`, because `body.tagName == "BODY"`. As we remember, `tagName` is always uppercase in HTML.
16-
2. The comment is now the only child node, so we get it in `body.firstChild`.
17-
3. The `data` property of the comment is its contents (inside `<!--...-->`): `"BODY"`.
15+
1. Le contenu de `<body>` est remplacé par le commentaire. Le commentaire est `<!--BODY-->`, car `body.tagName == "BODY"`. Comme nous nous en souvenons, `tagName` est toujours en majuscule en HTML.
16+
2. Le commentaire est maintenant le seul nœud enfant, donc nous l'avons dans `body.firstChild`.
17+
3. La propriété `data` du commentaire est son contenu (à l'intérieur `<!--...-->`) : `"BODY"`.

2-ui/1-document/05-basic-dom-node-properties/3-tag-in-comment/task.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@ importance: 3
22

33
---
44

5-
# Tag in comment
5+
# Balise dans le commentaire
66

7-
What does this code show?
7+
Qu'affice ce code ?
88

99
```html
1010
<script>
1111
let body = document.body;
1212
1313
body.innerHTML = "<!--" + body.tagName + "-->";
1414
15-
alert( body.firstChild.data ); // what's here?
15+
alert( body.firstChild.data ); // Qu'est ce qu'il y a ici ?
1616
</script>
1717
```
Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,40 @@
11

2-
We can see which class it belongs by outputting it, like:
2+
Nous pouvons voir à quelle classe il appartient en le sortant, comme :
33

44
```js run
55
alert(document); // [object HTMLDocument]
66
```
77

8-
Or:
8+
Ou :
99

1010
```js run
1111
alert(document.constructor.name); // HTMLDocument
1212
```
1313

14-
So, `document` is an instance of `HTMLDocument` class.
14+
Ainsi, `document` est une instance de la classe `HTMLDocument`.
1515

16-
What's its place in the hierarchy?
16+
Quelle est sa place dans la hiérarchie ?
1717

18-
Yeah, we could browse the specification, but it would be faster to figure out manually.
18+
Oui, nous pourrions parcourir les spécifications, mais il serait plus rapide de le déterminer manuellement.
1919

20-
Let's traverse the prototype chain via `__proto__`.
20+
Parcourons la chaîne du prototype via `__proto__`.
2121

22-
As we know, methods of a class are in the `prototype` of the constructor. For instance, `HTMLDocument.prototype` has methods for documents.
22+
Comme nous le savons, les méthodes d'une classe sont dans le `prototype` du constructeur. Par exemple, `HTMLDocument.prototype` a des méthodes pour les documents.
2323

24-
Also, there's a reference to the constructor function inside the `prototype`:
24+
De plus, il y a une référence à la fonction constructeur à l'intérieur du `prototype` :
2525

2626
```js run
2727
alert(HTMLDocument.prototype.constructor === HTMLDocument); // true
2828
```
2929

30-
To get a name of the class as a string, we can use `constructor.name`. Let's do it for the whole `document` prototype chain, till class `Node`:
30+
Pour obtenir le nom de la classe sous forme de chaîne de caractères, nous pouvons utiliser `constructor.name`. Faisons-le pour toute la chaîne du prototype de `document`, jusqu'à la classe` Node`:
3131

3232
```js run
3333
alert(HTMLDocument.prototype.constructor.name); // HTMLDocument
3434
alert(HTMLDocument.prototype.__proto__.constructor.name); // Document
3535
alert(HTMLDocument.prototype.__proto__.__proto__.constructor.name); // Node
3636
```
3737

38-
That's the hierarchy.
38+
Voilà la hiérarchie.
3939

40-
We also could examine the object using `console.dir(document)` and see these names by opening `__proto__`. The console takes them from `constructor` internally.
40+
Nous pourrions également examiner l'objet en utilisant `console.dir(document)` et voir ces noms en ouvrant `__proto__`. La console les prend du constructeur en interne.

2-ui/1-document/05-basic-dom-node-properties/4-where-document-in-hierarchy/task.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ importance: 4
22

33
---
44

5-
# Where's the "document" in the hierarchy?
5+
# Où est le "document" dans la hiérarchie ?
66

7-
Which class does the `document` belong to?
7+
À quelle classe appartient le `document` ?
88

9-
What's its place in the DOM hierarchy?
9+
Quelle est sa place dans la hiérarchie DOM ?
1010

11-
Does it inherit from `Node` or `Element`, or maybe `HTMLElement`?
11+
Hérite-t-il de `Node` ou` Element`, ou peut-être de `HTMLElement` ?

0 commit comments

Comments
 (0)