Skip to content

Commit 073baa9

Browse files
committed
Update 2-ui/1-document/05-basic-dom-node-properties/article.md
1 parent 9c69ccb commit 073baa9

File tree

1 file changed

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

1 file changed

+36
-38
lines changed

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

Lines changed: 36 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ In questo capitolo vedremo meglio cosa sono e impareremo le loro proprietà più
88

99
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.
1010

11-
Ogni nodo del DOM appartiene alla corrispondente classe integrata.
11+
Ogni nodo del DOM appartiene alla corrispondente classe nativa.
1212

1313
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.
1414

@@ -117,89 +117,87 @@ interface HTMLInputElement: HTMLElement {
117117
118118
## La proprietà "nodeType"
119119
120-
The `nodeType` property provides one more, "old-fashioned" way to get the "type" of a DOM node.
120+
La proprietà `nodeType` offre un altro modo "vecchio stile" per ricavare il "tipo" di un nodo DOM.
121121
122-
It has a numeric value:
123-
- `elem.nodeType == 1` for element nodes,
124-
- `elem.nodeType == 3` for text nodes,
125-
- `elem.nodeType == 9` for the document object,
126-
- there are few other values in [the specification](https://dom.spec.whatwg.org/#node).
122+
Ha un valore numerico:
123+
- `elem.nodeType == 1` per i nodi elemento,
124+
- `elem.nodeType == 3` per i nodi testo,
125+
- `elem.nodeType == 9` per l'oggetto documento,
126+
- c'è qualche altro valore nella [specifica](https://dom.spec.whatwg.org/#node).
127127
128-
For instance:
128+
Per esempio:
129129
130130
```html run
131131
<body>
132132
<script>
133133
let elem = document.body;
134134
135-
// let's examine what it is?
136-
alert(elem.nodeType); // 1 => element
135+
// esaminiamo di cosa si tratta
136+
alert(elem.nodeType); // 1 => nodo elemento
137137
138-
// and the first child is...
139-
alert(elem.firstChild.nodeType); // 3 => text
138+
// e il primo nodo figlio è...
139+
alert(elem.firstChild.nodeType); // 3 => nodo testo
140140
141-
// for the document object, the type is 9
141+
// per l'oggetto documento il tipo è 9
142142
alert( document.nodeType ); // 9
143143
</script>
144144
</body>
145145
```
146146
147-
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.
148148
149-
## Tag: nodeName and tagName
149+
## Tag: nodeName e tagName
150150
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`:
152152
153-
For instance:
153+
Per esempio:
154154
155155
```js run
156156
alert( document.body.nodeName ); // BODY
157157
alert( document.body.tagName ); // BODY
158158
```
159159
160-
Is there any difference between `tagName` and `nodeName`?
160+
Esiste una differenza tra `tagName` e `nodeName`?
161161
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.
163163
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.
168168
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.
172170
171+
Per esempio paragoniamo `tagName` e `nodeName` per `document` e per un commento:
173172
174173
```html run
175174
<body><!-- comment -->
176175
177176
<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)
180179
alert( document.body.firstChild.nodeName ); // #comment
181180
182-
// for document
183-
alert( document.tagName ); // undefined (not an element)
181+
// per il documento
182+
alert( document.tagName ); // undefined (non si tratta di un elemento)
184183
alert( document.nodeName ); // #document
185184
</script>
186185
</body>
187186
```
188187
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`
190189
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`.
193192
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>`.
195194
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.
197196
```
198197
198+
## innerHTML: i contenuti
199199
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.
203201
204202
We can also modify it. So it's one of the most powerful ways to change the page.
205203

0 commit comments

Comments
 (0)