Skip to content

Commit ead3c54

Browse files
authored
Merge pull request #422 from homero304/Node-properties_type-tag-and-contents
Node properties: type, tag and contents
2 parents cab278a + 0c5fede commit ead3c54

File tree

11 files changed

+263
-263
lines changed

11 files changed

+263
-263
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+
Aquí hay una trampa.
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+
En el momento de la ejecución de `<script>`, el último nodo DOM es exactamente `<script>`, porque el navegador aún no procesó el resto de la página.
44

5-
So the result is `1` (element node).
5+
Entonces el resultado es `1` (nodo de elemento).
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é hay en nodeType?
66

7-
What does the script show?
7+
¿Qué muestra el 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+
Hagamos un ciclo sobre `<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+
En el ciclo, necesitamos introducir el texto dentro de cada `li`.
1010

11-
We can read the text from the first child node of `li`, that is the text node:
11+
Podemos leer el texto del primer nodo hijo de `li`, que es el nodo de texto:
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+
// el título es el texto en <li> antes de cualquier otro nodo
1818
}
1919
```
2020

21-
Then we can get the number of descendants as `li.getElementsByTagName('li').length`.
21+
Entonces podemos obtener el número de descendientes como `li.getElementsByTagName('li').length`.

2-ui/1-document/05-basic-dom-node-properties/2-tree-info/solution.view/index.html

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,36 +3,36 @@
33
<body>
44

55
<ul>
6-
<li>Animals
6+
<li>Animales
77
<ul>
8-
<li>Mammals
8+
<li>Mamíferos
99
<ul>
10-
<li>Cows</li>
11-
<li>Donkeys</li>
12-
<li>Dogs</li>
13-
<li>Tigers</li>
10+
<li>Vacas</li>
11+
<li>Burros</li>
12+
<li>Perros</li>
13+
<li>Tigres</li>
1414
</ul>
1515
</li>
16-
<li>Other
16+
<li>Otros
1717
<ul>
18-
<li>Snakes</li>
19-
<li>Birds</li>
20-
<li>Lizards</li>
18+
<li>Serpientes</li>
19+
<li>Aves</li>
20+
<li>Lagartos</li>
2121
</ul>
2222
</li>
2323
</ul>
2424
</li>
25-
<li>Fishes
25+
<li>Peces
2626
<ul>
27-
<li>Aquarium
27+
<li>Acuario
2828
<ul>
2929
<li>Guppy</li>
30-
<li>Angelfish</li>
30+
<li>Angelote</li>
3131
</ul>
3232
</li>
33-
<li>Sea
33+
<li>Mar
3434
<ul>
35-
<li>Sea trout</li>
35+
<li>Trucha de mar</li>
3636
</ul>
3737
</li>
3838
</ul>
@@ -41,12 +41,12 @@
4141

4242
<script>
4343
for (let li of document.querySelectorAll('li')) {
44-
// get the title from the text node
44+
// obtener el título del nodo de texto
4545
let title = li.firstChild.data;
4646

47-
title = title.trim(); // remove extra spaces from ends
47+
title = title.trim(); // eliminar los espacios adicionales de los extremos
4848

49-
// get the descendants count
49+
// obtener el recuento de descendientes
5050
let count = li.getElementsByTagName('li').length;
5151

5252
alert(title + ': ' + count);

2-ui/1-document/05-basic-dom-node-properties/2-tree-info/source.view/index.html

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,44 +3,44 @@
33
<body>
44

55
<ul>
6-
<li>Animals
6+
<li>Animales
77
<ul>
8-
<li>Mammals
8+
<li>Mamíferos
99
<ul>
10-
<li>Cows</li>
11-
<li>Donkeys</li>
12-
<li>Dogs</li>
13-
<li>Tigers</li>
10+
<li>Vacas</li>
11+
<li>Burros</li>
12+
<li>Perros</li>
13+
<li>Tigres</li>
1414
</ul>
1515
</li>
16-
<li>Other
16+
<li>Otros
1717
<ul>
18-
<li>Snakes</li>
19-
<li>Birds</li>
20-
<li>Lizards</li>
18+
<li>Serpientes</li>
19+
<li>Aves</li>
20+
<li>Lagartos</li>
2121
</ul>
2222
</li>
2323
</ul>
2424
</li>
25-
<li>Fishes
25+
<li>Peces
2626
<ul>
27-
<li>Aquarium
27+
<li>Acuario
2828
<ul>
2929
<li>Guppy</li>
30-
<li>Angelfish</li>
30+
<li>Angelote</li>
3131
</ul>
3232
</li>
33-
<li>Sea
33+
<li>Mar
3434
<ul>
35-
<li>Sea trout</li>
35+
<li>Trucha de mar</li>
3636
</ul>
3737
</li>
3838
</ul>
3939
</li>
4040
</ul>
4141

4242
<script>
43-
// ... your code...
43+
// ... tu código...
4444
</script>
4545

4646
</body>

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+
# Contar los descendientes
66

7-
There's a tree structured as nested `ul/li`.
7+
Hay un árbol estructurado como `ul/li` anidado.
88

9-
Write the code that for each `<li>` shows:
9+
Escribe el código que para cada `<li>` muestra:
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. ¿Cuál es el texto dentro de él (sin el subárbol)?
12+
2. El número de `<li>` anidados: todos los descendientes, incluidos los profundamente anidados.
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 respuesta: **`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+
¿Qué está pasando paso a paso?
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. El contenido de `<body>` se reemplaza con el comentario. El comentario es `<!--BODY-->`, porque `body.tagName == "BODY"`. Como recordamos, `tagName` siempre está en mayúsculas en HTML.
16+
2. El comentario es ahora el único nodo hijo, así que lo obtenemos en `body.firstChild`.
17+
3. La propiedad `data` del comentario es su contenido (dentro de `<!--...-->`): `"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+
# Etiqueta en comentario
66

7-
What does this code show?
7+
¿Qué muestra este código?
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é hay aquí?
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+
Podemos ver a qué clase pertenece, imprimiéndola, así:
33

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

8-
Or:
8+
O:
99

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

14-
So, `document` is an instance of `HTMLDocument` class.
14+
Entonces, `document` es una instancia de la clase `HTMLDocument`.
1515

16-
What's its place in the hierarchy?
16+
¿Cuál es su lugar en la jerarquía?
1717

18-
Yeah, we could browse the specification, but it would be faster to figure out manually.
18+
Sí, podríamos examinar las especificaciones, pero sería más rápido averiguarlo manualmente.
1919

20-
Let's traverse the prototype chain via `__proto__`.
20+
Recorramos la cadena de prototype través de `__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+
Como sabemos, los métodos de una clase están en el `prototype` del constructor. Por ejemplo, `HTMLDocument.prototype` tiene métodos para documentos.
2323

24-
Also, there's a reference to the constructor function inside the `prototype`:
24+
Además, hay una referencia a la función constructor dentro de `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+
Para obtener un nombre de la clase como string, podemos usar `constructor.name`. Hagámoslo para toda la cadena prototype de `document`, hasta la clase `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+
Esa es la jerarquía.
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+
También podríamos examinar el objeto usando `console.dir(document)` y ver estos nombres abriendo `__proto__`. La consola los toma del `constructor` internamente.

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+
# ¿Dónde está el "document" en la jerarquía?
66

7-
Which class does the `document` belong to?
7+
¿A qué clase pertenece el `document`?
88

9-
What's its place in the DOM hierarchy?
9+
¿Cuál es su lugar en la jerarquía DOM?
1010

11-
Does it inherit from `Node` or `Element`, or maybe `HTMLElement`?
11+
¿Hereda de `Node` o `Element`, o tal vez `HTMLElement`?

0 commit comments

Comments
 (0)