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
+36-38Lines changed: 36 additions & 38 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -8,7 +8,7 @@ In questo capitolo vedremo meglio cosa sono e impareremo le loro proprietà più
8
8
9
9
Nodi del DOM differenti possono avere proprietà differenti. Ad esempio, un nodo elemento corrispondente ad un tag `<a>` avrà proprietà tipiche dei link ed un nodo corrispondente al tag `<input>` avrà proprietà tipiche dei campi di testo e così via. I nodi di testo sono differenti dai nodi elemento, tuttavia condividono anche proprietà e metodi comuni a tutti perché tutte le classi dei nodi del DOM costituiscono un'unica gerarchia.
10
10
11
-
Ogni nodo del DOM appartiene alla corrispondente classe integrata.
11
+
Ogni nodo del DOM appartiene alla corrispondente classe nativa.
12
12
13
13
La classe base della gerarchia è [EventTarget](https://dom.spec.whatwg.org/#eventtarget), che è ereditata dalla classe [Node](http://dom.spec.whatwg.org/#interface-node) che, a sua volta, è ereditata dalle altre classi corrispondenti ai nodi del DOM.
In modern scripts, we can use `instanceof` and other class-based tests to see the node type, but sometimes `nodeType` may be simpler. We can only read `nodeType`, not change it.
147
+
Nel codice moderno possiamo usare `instanceof` e altri test basati sulle classi per ottenere il tipo di nodo, ma, talvolta, può risultare più semplice l'uso di `nodeType`. La proprietà `nodeType` è in sola lettura, non possiamo modificarla.
148
148
149
-
## Tag: nodeName and tagName
149
+
## Tag: nodeName e tagName
150
150
151
-
Given a DOM node, we can read its tag name from `nodeName` or `tagName` properties:
151
+
Dato un nodo DOM, possiamo leggerne il tag tramite le proprietà `nodeName` o `tagName`:
152
152
153
-
For instance:
153
+
Per esempio:
154
154
155
155
```js run
156
156
alert( document.body.nodeName ); // BODY
157
157
alert( document.body.tagName ); // BODY
158
158
```
159
159
160
-
Is there any difference between `tagName` and `nodeName`?
160
+
Esiste una differenza tra `tagName` e `nodeName`?
161
161
162
-
Sure, the difference is reflected in their names, but is indeed a bit subtle.
162
+
Certamente, i nomi stessi delle proprietà suggeriscono la sottile differenza.
163
163
164
-
- The `tagName` property exists only for `Element` nodes.
165
-
- The `nodeName` is defined for any `Node`:
166
-
- for elements it means the same as `tagName`.
167
-
- for other node types (text, comment, etc.) it has a string with the node type.
164
+
- La proprietà `tagName` esiste solo per i nodi `Element`.
165
+
- La proprietà `nodeName` è definita per ogni `Node`:
166
+
- per i nodi elemento ha lo stesso valore di `tagName`.
167
+
- per gli altri tipi di nodo (testo, commento, ecc.) contiene una stringa che indica il tipo di nodo.
168
168
169
-
In other words, `tagName` is only supported by element nodes (as it originates from `Element` class), while `nodeName` can say something about other node types.
170
-
171
-
For instance, let's compare `tagName` and `nodeName` for the `document` and a comment node:
169
+
In altre parole, `tagName` è supportata solo dai nodi elemento (poiché ha origine dalla classe `Element`), mentre `nodeName` riesce a dare un'indicazione sugli altri tipi di nodo.
172
170
171
+
Per esempio paragoniamo `tagName` e `nodeName` per `document` e per un commento:
173
172
174
173
```html run
175
174
<body><!-- comment -->
176
175
177
176
<script>
178
-
// for comment
179
-
alert( document.body.firstChild.tagName ); // undefined (not an element)
177
+
// per un commento
178
+
alert( document.body.firstChild.tagName ); // undefined (non si tratta di un elemento)
alert( document.tagName ); // undefined (not an element)
181
+
// per il documento
182
+
alert( document.tagName ); // undefined (non si tratta di un elemento)
184
183
alert( document.nodeName ); // #document
185
184
</script>
186
185
</body>
187
186
```
188
187
189
-
If we only deal with elements, then we can use both `tagName` and `nodeName` - there's no difference.
188
+
Se abbiamo a che fare solo con elementi allora possiamo usare senza distinzione `tagName` e `nodeName`
190
189
191
-
```smart header="The tag name is always uppercase except in XML mode"
192
-
The browser has two modes of processing documents: HTML and XML. Usually the HTML-mode is used for webpages. XML-mode is enabled when the browser receives an XML-document with the header: `Content-Type: application/xml+xhtml`.
190
+
```smart header="Il nome del tag è sempre in maiuscolo tranne che nell'XML"
191
+
Il browser ha due modalità di elaborazione dei documenti: HTML e XML. Solitamente per le pagine web usa la modalità HTML. La modalità XML è abilitata quando il browser riceve un documento XML con l'intestazione `Content-Type: application/xml+xhtml`.
193
192
194
-
In HTML mode `tagName/nodeName` is always uppercased: it's `BODY` either for `<body>` or `<BoDy>`.
193
+
In modalità HTML `tagName/nodeName` è sempre maiuscola: restituisce `BODY` sia per `<body>` sia per `<BoDy>`.
195
194
196
-
In XML mode the case is kept "as is". Nowadays XML mode is rarely used.
195
+
In modalità XML il case viene mantenuto "così com'è". Ai giorni nostri la modalità XML è usata raramente.
197
196
```
198
197
198
+
## innerHTML: i contenuti
199
199
200
-
## innerHTML: the contents
201
-
202
-
The [innerHTML](https://w3c.github.io/DOM-Parsing/#the-innerhtml-mixin) property allows to get the HTML inside the element as a string.
200
+
La proprietà [innerHTML](https://w3c.github.io/DOM-Parsing/#the-innerhtml-mixin) consente di ottenere una stringa dell'HTML dentro l'elemento.
203
201
204
202
We can also modify it. So it's one of the most powerful ways to change the page.
0 commit comments