Skip to content

Commit 4367598

Browse files
committed
Update 2-ui/1-document/05-basic-dom-node-properties/article.md
1 parent 6c26147 commit 4367598

File tree

1 file changed

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

1 file changed

+42
-42
lines changed

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

Lines changed: 42 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -197,83 +197,83 @@ In modalità XML il case viene mantenuto "così com'è". Ai giorni nostri la mod
197197
198198
## innerHTML: i contenuti
199199
200-
La proprietà [innerHTML](https://w3c.github.io/DOM-Parsing/#the-innerhtml-mixin) consente di ottenere una stringa dell'HTML dentro l'elemento.
200+
La proprietà [innerHTML](https://w3c.github.io/DOM-Parsing/#the-innerhtml-mixin) consente di ottenere una stringa contenente l'HTML dentro l'elemento.
201201
202-
We can also modify it. So it's one of the most powerful ways to change the page.
202+
Possiamo anche modificarla e pertanto è uno dei più potenti strumenti per cambiare la pagina.
203203
204-
The example shows the contents of `document.body` and then replaces it completely:
204+
L'esempio mostra il contenuto di `document.body` e quindi lo rimpiazza completamente:
205205
206206
```html run
207207
<body>
208208
<p>A paragraph</p>
209209
<div>A div</div>
210210
211211
<script>
212-
alert( document.body.innerHTML ); // read the current contents
213-
document.body.innerHTML = 'The new BODY!'; // replace it
212+
alert( document.body.innerHTML ); // legge il contenuto corrente
213+
document.body.innerHTML = 'The new BODY!'; // lo rimpiazza
214214
</script>
215215
216216
</body>
217217
```
218218
219-
We can try to insert invalid HTML, the browser will fix our errors:
219+
Se proviamo a inserire HTML non valido, il browser correggerà i nostri errori:
220220
221221
```html run
222222
<body>
223223
224224
<script>
225-
document.body.innerHTML = '<b>test'; // forgot to close the tag
226-
alert( document.body.innerHTML ); // <b>test</b> (fixed)
225+
document.body.innerHTML = '<b>test'; // tag non chiuso correttamente
226+
alert( document.body.innerHTML ); // <b>test</b> (corretto)
227227
</script>
228228
229229
</body>
230230
```
231231
232-
```smart header="Scripts don't execute"
233-
If `innerHTML` inserts a `<script>` tag into the document -- it becomes a part of HTML, but doesn't execute.
232+
```smart header="I tag <script> non vengono eseguiti"
233+
Se `innerHTML` inserisce un tag `<script>` nel documento -- esso diviene parte dell'HTML ma non viene eseguito.
234234
```
235235
236-
### Beware: "innerHTML+=" does a full overwrite
236+
### Attenzione: "innerHTML+=" esegue una sovrascrittura completa
237237
238-
We can append HTML to an element by using `elem.innerHTML+="more html"`.
238+
Possiamo aggiungere HTML a un elemento usando `elem.innerHTML+="more html"`.
239239
240-
Like this:
240+
In questo modo:
241241
242242
```js
243243
chatDiv.innerHTML += "<div>Hello<img src='smile.gif'/> !</div>";
244244
chatDiv.innerHTML += "How goes?";
245245
```
246246
247-
But we should be very careful about doing it, because what's going on is *not* an addition, but a full overwrite.
247+
Tuttavia dovremmo stare molto attenti nel fare un'operazione del genere, perché *non* stiamo facendo una semplice aggiunta ma una sovrascrittura completa.
248248
249-
Technically, these two lines do the same:
249+
Tecnicamente queste due righe sono equivalenti:
250250
251251
```js
252252
elem.innerHTML += "...";
253-
// is a shorter way to write:
253+
// è un modo più rapido di scrivere:
254254
*!*
255255
elem.innerHTML = elem.innerHTML + "..."
256256
*/!*
257257
```
258258
259-
In other words, `innerHTML+=` does this:
259+
In altre parole, `innerHTML+=` fa questo:
260260
261-
1. The old contents is removed.
262-
2. The new `innerHTML` is written instead (a concatenation of the old and the new one).
261+
1. Rimuove il contenuto precedente.
262+
2. Il nuovo valore di `innerHTML` è inserito al suo posto (una concatenazione del vecchio e del nuovo).
263263
264-
**As the content is "zeroed-out" and rewritten from the scratch, all images and other resources will be reloaded**.
264+
**Poiché il contenuto viene "azzerato" e riscritto da zero, tutte le immagini e le altre risorse verranno ricaricate**.
265265
266-
In the `chatDiv` example above the line `chatDiv.innerHTML+="How goes?"` re-creates the HTML content and reloads `smile.gif` (hope it's cached). If `chatDiv` has a lot of other text and images, then the reload becomes clearly visible.
266+
Nell'esempio `chatDiv` sopra, la linea `chatDiv.innerHTML+="How goes?"` ricrea il contenuto HTML e ricarica `smile.gif` (speriamo sia in cache). Se `chatDiv` ha molto altro testo e immagini, in quel caso, il tempo di ricaricamento potrebbe diventare chiaramente percepibile.
267267
268-
There are other side-effects as well. For instance, if the existing text was selected with the mouse, then most browsers will remove the selection upon rewriting `innerHTML`. And if there was an `<input>` with a text entered by the visitor, then the text will be removed. And so on.
268+
Ci sono anche altri effetti collaterali. Per esempio, se il testo esistente era stato selezionato con il mouse, la maggior parte dei browser rimuoveranno la selezione al momento della riscrittura con `innerHTML`. Se un elemento `<input>` conteneva un testo digitato dal visitatore il testo sarà rimosso, e altri casi simili.
269269
270-
Luckily, there are other ways to add HTML besides `innerHTML`, and we'll study them soon.
270+
Fortunatamente ci sono altri modi di aggiungere HTML oltre che con `innerHTML`, presto li studieremo.
271271
272-
## outerHTML: full HTML of the element
272+
## outerHTML: l'HTML completo di un elemento
273273
274-
The `outerHTML` property contains the full HTML of the element. That's like `innerHTML` plus the element itself.
274+
La proprietà `outerHTML` contiene tutto l'HTML di un elemento. In pratica equivale a `innerHTML` più l'elemento stesso.
275275
276-
Here's an example:
276+
Di seguito un esempio:
277277
278278
```html run
279279
<div id="elem">Hello <b>World</b></div>
@@ -283,11 +283,11 @@ Here's an example:
283283
</script>
284284
```
285285
286-
**Beware: unlike `innerHTML`, writing to `outerHTML` does not change the element. Instead, it replaces it in the DOM.**
286+
**Attenzione: diversamente da `innerHTML`, la scrittura in `outerHTML` non cambia l'elemento ma lo sostituisce nel DOM.**
287287
288-
Yeah, sounds strange, and strange it is, that's why we make a separate note about it here. Take a look.
288+
Proprio così, sembra strano, e lo è. Ecco perché ne parliamo subito con una nota a parte. Prestate attenzione.
289289
290-
Consider the example:
290+
Considerate l'esempio:
291291
292292
```html run
293293
<div>Hello, world!</div>
@@ -296,35 +296,35 @@ Consider the example:
296296
let div = document.querySelector('div');
297297
298298
*!*
299-
// replace div.outerHTML with <p>...</p>
299+
// sostituisce div.outerHTML con <p>...</p>
300300
*/!*
301301
div.outerHTML = '<p>A new element</p>'; // (*)
302302
303303
*!*
304-
// Wow! 'div' is still the same!
304+
// Wow! 'div' non è cambiato!
305305
*/!*
306306
alert(div.outerHTML); // <div>Hello, world!</div> (**)
307307
</script>
308308
```
309309
310-
Looks really odd, right?
310+
Sembra davvero strano, vero?
311311
312-
In the line `(*)` we replaced `div` with `<p>A new element</p>`. In the outer document (the DOM) we can see the new content instead of the `<div>`. But, as we can see in line `(**)`, the value of the old `div` variable hasn't changed!
312+
Nella linea `(*)` sostituiamo `div` con `<p>A new element</p>`. Nel documento (il DOM) possiamo osservare che il nuovo contenuto ha preso il posto di `<div>`. Tuttavia, come possiamo notare nella linea `(**)`, il precedente valore della variabile `div`non è cambiato!
313313
314-
The `outerHTML` assignment does not modify the DOM element (the object referenced by, in this case, the variable 'div'), but removes it from the DOM and inserts the new HTML in its place.
314+
L'assegnazione con `outerHTML` non cambia l'elemento (cioè l'oggetto a cui fa riferimento, in questo caso, la variabile 'div'), però lo rimuove dal DOM e inserisce il nuovo HTML al suo posto.
315315
316-
So what happened in `div.outerHTML=...` is:
317-
- `div` was removed from the document.
318-
- Another piece of HTML `<p>A new element</p>` was inserted in its place.
319-
- `div` still has its old value. The new HTML wasn't saved to any variable.
316+
Ricapitolando ciò che è successo in `div.outerHTML=...` è:
317+
- `div` è stato rimosso dal documento.
318+
- Un pezzo di HTML differente `<p>A new element</p>` è stato inserito al suo posto.
319+
- `div` mantiene ancora il suo valore precedente. L'HTML inserito in seguito non è stato memorizzato in alcuna variabile.
320320
321-
It's so easy to make an error here: modify `div.outerHTML` and then continue to work with `div` as if it had the new content in it. But it doesn't. Such thing is correct for `innerHTML`, but not for `outerHTML`.
321+
È molto semplice commettere un errore a questo punto: modificare `div.outerHTML` e procedere con `div` come se avesse recepito il nuovo contenuto. Ma questo non avviene. Tale convinzione è corretta per `innerHTML`, ma non per `outerHTML`.
322322
323-
We can write to `elem.outerHTML`, but should keep in mind that it doesn't change the element we're writing to ('elem'). It puts the new HTML in its place instead. We can get references to the new elements by querying the DOM.
323+
Possiamo scrivere tramite `elem.outerHTML`, ma dovremmo tenere bene presente che non cambia l'elemento ('elem') su cui stiamo scrivendo, sostituisce invece il nuovo HTML al suo posto. Per avere un riferimento valido al nuovo elemento dobbiamo interrogare nuovamente il DOM.
324324
325-
## nodeValue/data: text node content
325+
## nodeValue/data: il contenuto testuale del nodo
326326
327-
The `innerHTML` property is only valid for element nodes.
327+
La proprietà `innerHTML` è valida soltanto per i nodi elemento.
328328
329329
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.
330330

0 commit comments

Comments
 (0)