You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: 2-ui/1-document/05-basic-dom-node-properties/article.md
+31-31Lines changed: 31 additions & 31 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -326,9 +326,9 @@ Possiamo scrivere tramite `elem.outerHTML`, ma dovremmo tenere bene presente che
326
326
327
327
La proprietà `innerHTML` è valida soltanto per i nodi elemento.
328
328
329
-
Other node types, such as text nodes, have their counterpart: `nodeValue` and `data` properties. These two are almost the same for practical use, there are only minor specification differences. So we'll use `data`, because it's shorter.
329
+
Gli altri tipi di nodo, come i nodi di testo, hanno il loro corrispettivo: le proprietà `nodeValue` e `data`. Nell'uso pratico questi due si comportano quasi alla stessa maniera, ci sono solo piccole differenze nella specifica. Useremo perciò `data` dal momento che è più breve.
330
330
331
-
An example of reading the content of a text node and a comment:
331
+
Ecco un esempio di lettura del contenuto di un nodo di testo e di un commento:
332
332
333
333
```html run height="50"
334
334
<body>
@@ -348,23 +348,23 @@ An example of reading the content of a text node and a comment:
348
348
</body>
349
349
```
350
350
351
-
For text nodes we can imagine a reason to read or modify them, but why comments?
351
+
Per i nodi di testo possiamo ipotizzare un motivo per leggerne o modificarne il contenuto testuale, ma perché i commenti?
352
352
353
-
Sometimes developers embed information or template instructions into HTML in them, like this:
353
+
Talvolta gli sviluppatori incorporano informazioni o istruzioni sui template nei commenti all'interno dell'HTML, in questo modo:
354
354
355
355
```html
356
356
<!-- if isAdmin -->
357
357
<div>Welcome, Admin!</div>
358
358
<!-- /if -->
359
359
```
360
360
361
-
...Then JavaScript can read it from `data` property and process embedded instructions.
361
+
...così JavaScript può leggerle tramite la proprietà `data` ed elaborare le istruzioni contenute.
362
362
363
-
## textContent: pure text
363
+
## textContent: solo il testo
364
364
365
-
The `textContent` provides access to the *text* inside the element: only text, minus all `<tags>`.
365
+
La proprietà `textContent` fornisce l'accesso al *testo* dentro l'elemento: solo il testo, al netto di tutti i `<tag>`.
366
366
367
-
For instance:
367
+
Per esempio:
368
368
369
369
```html run
370
370
<div id="news">
@@ -378,18 +378,18 @@ For instance:
378
378
</script>
379
379
```
380
380
381
-
As we can see, only text is returned, as if all `<tags>` were cut out, but the text in them remained.
381
+
Come possiamo notare viene restituito solo il testo, come se tutti i `<tag>` fossero stati eliminati, ma il testo in essi fosse rimasto.
382
382
383
-
In practice, reading such text is rarely needed.
383
+
Leggere il testo in questa maniera è un'esigenza rara nell'uso pratico.
384
384
385
-
**Writing to `textContent` is much more useful, because it allows to write text the "safe way".**
385
+
**È molto più utile scrivere con `textContent`, perché consente di inserire testo "in sicurezza".**
386
386
387
-
Let's say we have an arbitrary string, for instance entered by a user, and want to show it.
387
+
Supponiamo di avere una stringa arbitraria, ad esempio inserita da un utente, e di volerla mostrare.
388
388
389
-
- With `innerHTML` we'll have it inserted "as HTML", with all HTML tags.
390
-
- With `textContent` we'll have it inserted "as text", all symbols are treated literally.
389
+
- Con `innerHTML` la inseriremo "come HTML", compresi tutti i tag HTML.
390
+
- Con `textContent` la inseriremo "come testo", tutti i simboli sono trattati letteralmente.
391
391
392
-
Compare the two:
392
+
Paragoniamo le due opzioni:
393
393
394
394
```html run
395
395
<div id="elem1"></div>
@@ -403,16 +403,16 @@ Compare the two:
403
403
</script>
404
404
```
405
405
406
-
1. The first `<div>` gets the name "as HTML": all tags become tags, so we see the bold name.
407
-
2. The second `<div>` gets the name "as text", so we literally see `<b>Winnie-the-Pooh!</b>`.
406
+
1. Il primo `<div>` riceve il nome "come HTML": tutti i tag diventano tali, perciò vedremo il nome in grassetto.
407
+
2. Il secondo `<div>` riceve il nome "come testo", perciò vedremo letteralmente `<b>Winnie-the-Pooh!</b>`.
408
408
409
-
In most cases, we expect the text from a user, and want to treat it as text. We don't want unexpected HTML in our site. An assignment to `textContent` does exactly that.
409
+
Nella maggior parte dei casi da un utente ci aspettiamo testo e desideriamo gestirlo in quanto tale. Non vogliamo codice HTML inatteso sul nostro sito. Un'assegnazione con `textContent` fa esattamente questo.
410
410
411
-
## The "hidden" property
411
+
## La proprietà "hidden"
412
412
413
-
The "hidden" attribute and the DOM property specifies whether the element is visible or not.
413
+
L'attributo "hidden" e la corrispettiva proprietà del DOM specificano se l'elemento debba essere visibile o meno.
414
414
415
-
We can use it in HTML or assign it using JavaScript, like this:
415
+
Possiamo agire da codice HTML o da JavaScript in questo modo:
416
416
417
417
```html run height="80"
418
418
<div>Both divs below are hidden</div>
@@ -426,9 +426,9 @@ We can use it in HTML or assign it using JavaScript, like this:
426
426
</script>
427
427
```
428
428
429
-
Technically, `hidden` works the same as `style="display:none"`. But it's shorter to write.
429
+
Tecnicamente, `hidden` funziona alla stessa maniera di `style="display:none"` ma è più breve da scrivere.
430
430
431
-
Here's a blinking element:
431
+
Ecco come ottenere un elemento lampeggiante:
432
432
433
433
434
434
```html run height=50
@@ -439,16 +439,16 @@ Here's a blinking element:
439
439
</script>
440
440
```
441
441
442
-
## More properties
442
+
## Altre proprietà
443
443
444
-
DOM elements also have additional properties, in particular those that depend on the class:
444
+
Gli elementi DOM hanno inoltre proprietà aggiuntive, in particolare quelle che dipendono dalla classe:
445
445
446
-
- `value` -- the value for `<input>`, `<select>` and `<textarea>` (`HTMLInputElement`, `HTMLSelectElement`...).
447
-
- `href` -- the "href" for `<a href="...">` (`HTMLAnchorElement`).
448
-
- `id` -- the value of "id" attribute, for all elements (`HTMLElement`).
449
-
- ...and much more...
446
+
- `value` -- il valore di `<input>`, `<select>` e `<textarea>` (`HTMLInputElement`, `HTMLSelectElement`...).
447
+
- `href` -- il valore dell'attributo "href" di `<a href="...">` (`HTMLAnchorElement`).
448
+
- `id` -- il valore dell'attributo "id" per tutti gli elementi (`HTMLElement`).
449
+
- ...e molte altre...
450
450
451
-
For instance:
451
+
Per esempio:
452
452
453
453
```html run height="80"
454
454
<input type="text" id="elem" value="value">
@@ -466,7 +466,7 @@ If we want to know the full list of supported properties for a given class, we c
466
466
467
467
Or if we'd like to get them fast or are interested in a concrete browser specification -- we can always output the element using `console.dir(elem)` and read the properties. Or explore "DOM properties" in the Elements tab of the browser developer tools.
468
468
469
-
## Summary
469
+
## Sommario
470
470
471
471
Each DOM node belongs to a certain class. The classes form a hierarchy. The full set of properties and methods come as the result of inheritance.
0 commit comments