Skip to content

Commit 7b53647

Browse files
committed
Update 2-ui/1-document/05-basic-dom-node-properties/article.md
1 parent 006d454 commit 7b53647

File tree

1 file changed

+31
-31
lines changed
  • 2-ui/1-document/05-basic-dom-node-properties

1 file changed

+31
-31
lines changed

2-ui/1-document/05-basic-dom-node-properties/article.md

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -326,9 +326,9 @@ Possiamo scrivere tramite `elem.outerHTML`, ma dovremmo tenere bene presente che
326326
327327
La proprietà `innerHTML` è valida soltanto per i nodi elemento.
328328
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.
330330
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:
332332
333333
```html run height="50"
334334
<body>
@@ -348,23 +348,23 @@ An example of reading the content of a text node and a comment:
348348
</body>
349349
```
350350
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?
352352
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:
354354
355355
```html
356356
<!-- if isAdmin -->
357357
<div>Welcome, Admin!</div>
358358
<!-- /if -->
359359
```
360360
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.
362362
363-
## textContent: pure text
363+
## textContent: solo il testo
364364
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>`.
366366
367-
For instance:
367+
Per esempio:
368368
369369
```html run
370370
<div id="news">
@@ -378,18 +378,18 @@ For instance:
378378
</script>
379379
```
380380
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.
382382
383-
In practice, reading such text is rarely needed.
383+
Leggere il testo in questa maniera è un'esigenza rara nell'uso pratico.
384384
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".**
386386
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.
388388
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.
391391
392-
Compare the two:
392+
Paragoniamo le due opzioni:
393393
394394
```html run
395395
<div id="elem1"></div>
@@ -403,16 +403,16 @@ Compare the two:
403403
</script>
404404
```
405405
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>`.
408408
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.
410410
411-
## The "hidden" property
411+
## La proprietà "hidden"
412412
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.
414414
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:
416416
417417
```html run height="80"
418418
<div>Both divs below are hidden</div>
@@ -426,9 +426,9 @@ We can use it in HTML or assign it using JavaScript, like this:
426426
</script>
427427
```
428428
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.
430430
431-
Here's a blinking element:
431+
Ecco come ottenere un elemento lampeggiante:
432432
433433
434434
```html run height=50
@@ -439,16 +439,16 @@ Here's a blinking element:
439439
</script>
440440
```
441441
442-
## More properties
442+
## Altre proprietà
443443
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:
445445
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...
450450
451-
For instance:
451+
Per esempio:
452452
453453
```html run height="80"
454454
<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
466466
467467
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.
468468
469-
## Summary
469+
## Sommario
470470
471471
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.
472472

0 commit comments

Comments
 (0)