From 385420f836752a19ba15f4e7db65f5cbc9768323 Mon Sep 17 00:00:00 2001 From: Marcello Date: Sat, 13 Mar 2021 15:45:28 +0100 Subject: [PATCH 01/16] Update 2-ui/1-document/05-basic-dom-node-properties/article.md --- .../05-basic-dom-node-properties/article.md | 34 +++++++++---------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/2-ui/1-document/05-basic-dom-node-properties/article.md b/2-ui/1-document/05-basic-dom-node-properties/article.md index fc3bf6525..b29ccad95 100644 --- a/2-ui/1-document/05-basic-dom-node-properties/article.md +++ b/2-ui/1-document/05-basic-dom-node-properties/article.md @@ -1,31 +1,31 @@ -# Node properties: type, tag and contents +# Le proprietà del nodo: tipo, tag e contenuto -Let's get a more in-depth look at DOM nodes. +Diamo uno sguardo più approfondito ai nodi del DOM. -In this chapter we'll see more into what they are and learn their most used properties. +In questo capitolo vedremo meglio cosa sono e impareremo le loro proprietà più utilizzate. -## DOM node classes +## Le classi dei nodi del DOM -Different DOM nodes may have different properties. For instance, an element node corresponding to tag `` has link-related properties, and the one corresponding to `` has input-related properties and so on. Text nodes are not the same as element nodes. But there are also common properties and methods between all of them, because all classes of DOM nodes form a single hierarchy. +Nodi del DOM differenti possono avere proprietà differenti. Ad esempio, un nodo elemento corrispondente ad un tag `` avrà proprietà tipiche dei link ed uno corrispondente al tag `` 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 loro perché tutte le classi dei nodi del DOM costituiscono un'unica gerarchia. -Each DOM node belongs to the corresponding built-in class. +Ogni nodo del DOM appartiene alla corrispondente classe integrata. -The root of the hierarchy is [EventTarget](https://dom.spec.whatwg.org/#eventtarget), that is inherited by [Node](http://dom.spec.whatwg.org/#interface-node), and other DOM nodes inherit from it. +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. -Here's the picture, explanations to follow: +Qui lo schema, le spiegazioni a seguire: ![](dom-class-hierarchy.svg) -The classes are: +Le classi sono: -- [EventTarget](https://dom.spec.whatwg.org/#eventtarget) -- is the root "abstract" class. Objects of that class are never created. It serves as a base, so that all DOM nodes support so-called "events", we'll study them later. -- [Node](http://dom.spec.whatwg.org/#interface-node) -- is also an "abstract" class, serving as a base for DOM nodes. It provides the core tree functionality: `parentNode`, `nextSibling`, `childNodes` and so on (they are getters). Objects of `Node` class are never created. But there are concrete node classes that inherit from it, namely: `Text` for text nodes, `Element` for element nodes and more exotic ones like `Comment` for comment nodes. -- [Element](http://dom.spec.whatwg.org/#interface-element) -- is a base class for DOM elements. It provides element-level navigation like `nextElementSibling`, `children` and searching methods like `getElementsByTagName`, `querySelector`. A browser supports not only HTML, but also XML and SVG. The `Element` class serves as a base for more specific classes: `SVGElement`, `XMLElement` and `HTMLElement`. -- [HTMLElement](https://html.spec.whatwg.org/multipage/dom.html#htmlelement) -- is finally the basic class for all HTML elements. It is inherited by concrete HTML elements: - - [HTMLInputElement](https://html.spec.whatwg.org/multipage/forms.html#htmlinputelement) -- the class for `` elements, - - [HTMLBodyElement](https://html.spec.whatwg.org/multipage/semantics.html#htmlbodyelement) -- the class for `` elements, - - [HTMLAnchorElement](https://html.spec.whatwg.org/multipage/semantics.html#htmlanchorelement) -- the class for `` elements, - - ...and so on, each tag has its own class that may provide specific properties and methods. +- [EventTarget](https://dom.spec.whatwg.org/#eventtarget) -- è la classe radice (root class) "astratta". Gli oggetti di questa classe non vengono mai creati. Serve solo come base, in questo modo tutti i nodi del DOM supportano i cosiddetti "eventi" che studieremo successivamente. +- [Node](http://dom.spec.whatwg.org/#interface-node) -- anche questa è una classe "astratta" che serve da base per i nodi del DOM. Fornisce le funzionalità principali della struttura gerarchica: `parentNode`, `nextSibling`, `childNodes` e così via (si tratta di getters). Dalla classe `Node` non vengono mai creati oggetti, tuttavia da questa ereditano classi corrispondenti a nodi concreti, nella fattispecie: `Text` per i nodi di testo, `Element` per i nodi elemento e quelli meno ricorrenti come `Comment` per i nodi commento. +- [Element](http://dom.spec.whatwg.org/#interface-element) -- è la classe base per gli elementi del DOM. Fornisce le funzionalità di navigazione tra elementi come `nextElementSibling`, `children` ed i metodi di ricerca come `getElementsByTagName`, `querySelector`. Un browser non supporta solo HTML, ma anche XML e SVG. La classe `Element` serve da base per le classi più specifiche: `SVGElement`, `XMLElement` e `HTMLElement`. +- [HTMLElement](https://html.spec.whatwg.org/multipage/dom.html#htmlelement) -- è, infine, la classe base per tutti gli elementi HTML. Essa è ereditata da elementi HTML concreti: + - [HTMLInputElement](https://html.spec.whatwg.org/multipage/forms.html#htmlinputelement) -- la classe per gli elementi ``, + - [HTMLBodyElement](https://html.spec.whatwg.org/multipage/semantics.html#htmlbodyelement) -- la classe per gli elementi ``, + - [HTMLAnchorElement](https://html.spec.whatwg.org/multipage/semantics.html#htmlanchorelement) -- la classe per gli elementi ``, + - ...e così via, ogni tag ha una propria classe che espone proprietà e metodi specifici. So, the full set of properties and methods of a given node comes as the result of the inheritance. From 0823b82829e0149d8977acdffb3cef206fc469ca Mon Sep 17 00:00:00 2001 From: Marcello Date: Sun, 14 Mar 2021 10:41:52 +0100 Subject: [PATCH 02/16] Update 2-ui/1-document/05-basic-dom-node-properties/article.md --- .../05-basic-dom-node-properties/article.md | 21 ++++++++++--------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/2-ui/1-document/05-basic-dom-node-properties/article.md b/2-ui/1-document/05-basic-dom-node-properties/article.md index b29ccad95..8a5f4a10e 100644 --- a/2-ui/1-document/05-basic-dom-node-properties/article.md +++ b/2-ui/1-document/05-basic-dom-node-properties/article.md @@ -6,7 +6,7 @@ In questo capitolo vedremo meglio cosa sono e impareremo le loro proprietà più ## Le classi dei nodi del DOM -Nodi del DOM differenti possono avere proprietà differenti. Ad esempio, un nodo elemento corrispondente ad un tag `` avrà proprietà tipiche dei link ed uno corrispondente al tag `` 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 loro perché tutte le classi dei nodi del DOM costituiscono un'unica gerarchia. +Nodi del DOM differenti possono avere proprietà differenti. Ad esempio, un nodo elemento corrispondente ad un tag `` avrà proprietà tipiche dei link ed un nodo corrispondente al tag `` 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. Ogni nodo del DOM appartiene alla corrispondente classe integrata. @@ -27,18 +27,19 @@ Le classi sono: - [HTMLAnchorElement](https://html.spec.whatwg.org/multipage/semantics.html#htmlanchorelement) -- la classe per gli elementi ``, - ...e così via, ogni tag ha una propria classe che espone proprietà e metodi specifici. -So, the full set of properties and methods of a given node comes as the result of the inheritance. +In definitiva, la lista completa delle proprietà e dei metodi di un nodo è il risultato dell'ereditarietà. -For example, let's consider the DOM object for an `` element. It belongs to [HTMLInputElement](https://html.spec.whatwg.org/multipage/forms.html#htmlinputelement) class. +Si consideri, ad esempio, l'oggetto DOM per un elemento `` che appartiene alla classe [HTMLInputElement](https://html.spec.whatwg.org/multipage/forms.html#htmlinputelement). -It gets properties and methods as a superposition of (listed in inheritance order): +Esso riceve proprietà e metodi per effetto della sovrapposizione di (elencate in ordine di ereditarietà): -- `HTMLInputElement` -- this class provides input-specific properties, -- `HTMLElement` -- it provides common HTML element methods (and getters/setters), -- `Element` -- provides generic element methods, -- `Node` -- provides common DOM node properties, -- `EventTarget` -- gives the support for events (to be covered), -- ...and finally it inherits from `Object`, so "plain object" methods like `hasOwnProperty` are also available. + +- `HTMLInputElement` -- questa classe fornisce le proprietà specifiche per un campo di testo, +- `HTMLElement` -- espone i metodi (e i getters/setters) comuni agli elementi HTML, +- `Element` -- fornisce i metodi generici propri di un elemento, +- `Node` -- fornisce i metodi generici propri di un nodo DOM, +- `EventTarget` -- consente il supporto agli eventi (che tratteremo in seguito), +- ...e, infine, esso eredita da `Object`, quindi saranno anche disponibili i metodi di un "oggetto semplice" come `hasOwnProperty`. To see the DOM node class name, we can recall that an object usually has the `constructor` property. It references the class constructor, and `constructor.name` is its name: From 21c26b825cef1e4ff433df0c305e398f1281fd74 Mon Sep 17 00:00:00 2001 From: Marcello Date: Sun, 14 Mar 2021 23:36:20 +0100 Subject: [PATCH 03/16] Update 2-ui/1-document/05-basic-dom-node-properties/article.md --- .../05-basic-dom-node-properties/article.md | 44 +++++++++---------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/2-ui/1-document/05-basic-dom-node-properties/article.md b/2-ui/1-document/05-basic-dom-node-properties/article.md index 8a5f4a10e..f5959abc5 100644 --- a/2-ui/1-document/05-basic-dom-node-properties/article.md +++ b/2-ui/1-document/05-basic-dom-node-properties/article.md @@ -29,7 +29,7 @@ Le classi sono: In definitiva, la lista completa delle proprietà e dei metodi di un nodo è il risultato dell'ereditarietà. -Si consideri, ad esempio, l'oggetto DOM per un elemento `` che appartiene alla classe [HTMLInputElement](https://html.spec.whatwg.org/multipage/forms.html#htmlinputelement). +Consideriamo, ad esempio, l'oggetto DOM per un elemento `` che appartiene alla classe [HTMLInputElement](https://html.spec.whatwg.org/multipage/forms.html#htmlinputelement). Esso riceve proprietà e metodi per effetto della sovrapposizione di (elencate in ordine di ereditarietà): @@ -41,19 +41,19 @@ Esso riceve proprietà e metodi per effetto della sovrapposizione di (elencate i - `EventTarget` -- consente il supporto agli eventi (che tratteremo in seguito), - ...e, infine, esso eredita da `Object`, quindi saranno anche disponibili i metodi di un "oggetto semplice" come `hasOwnProperty`. -To see the DOM node class name, we can recall that an object usually has the `constructor` property. It references the class constructor, and `constructor.name` is its name: +Per conoscere il nome della classe di un nodo DOM, ricordiamoci che un oggetto ha solitamente la proprietà `constructor`. Questa si riferisce al costruttore della classe e il suo nome è `constructor.name`: ```js run alert( document.body.constructor.name ); // HTMLBodyElement ``` -...Or we can just `toString` it: +...O possiamo semplicemente eseguire il metodo `toString`: ```js run alert( document.body ); // [object HTMLBodyElement] ``` -We also can use `instanceof` to check the inheritance: +Possiamo inoltre usare `instanceof` per verificare l'ereditarietà: ```js run alert( document.body instanceof HTMLBodyElement ); // true @@ -63,38 +63,38 @@ alert( document.body instanceof Node ); // true alert( document.body instanceof EventTarget ); // true ``` -As we can see, DOM nodes are regular JavaScript objects. They use prototype-based classes for inheritance. +Come possiamo notare i nodi DOM sono regolari oggetti JavaScript ed usano classi basate sui prototipi per l'ereditarietà. -That's also easy to see by outputting an element with `console.dir(elem)` in a browser. There in the console you can see `HTMLElement.prototype`, `Element.prototype` and so on. +Questo è anche facile da osservare esaminando un elemento in un browser con `console.dir(elem)`. Nella console potremo vedere `HTMLElement.prototype`, `Element.prototype` e così via. ```smart header="`console.dir(elem)` versus `console.log(elem)`" -Most browsers support two commands in their developer tools: `console.log` and `console.dir`. They output their arguments to the console. For JavaScript objects these commands usually do the same. +La maggior parte dei browser supportano due comandi nei loro strumenti di sviluppo: `console.log` e `console.dir` che mostrano in console i loro argomenti. Per quanto riguarda gli oggetti JavaScript solitamente questi comandi funzionano allo stesso modo. -But for DOM elements they are different: +Ma per gli elementi DOM sono differenti: -- `console.log(elem)` shows the element DOM tree. -- `console.dir(elem)` shows the element as a DOM object, good to explore its properties. +- `console.log(elem)` mostra l'alberatura DOM dell'elemento. +- `console.dir(elem)` mostra l'elemento come oggetto DOM, ottimo per esplorarne le proprietà. -Try it on `document.body`. +Provatelo con `document.body`. ``` -````smart header="IDL in the spec" -In the specification, DOM classes aren't described by using JavaScript, but a special [Interface description language](https://en.wikipedia.org/wiki/Interface_description_language) (IDL), that is usually easy to understand. +````smart header="L'IDL della specifica" +Nella specifica, le classi DOM non sono descritte con JavaScript, ma con uno speciale [Interface description language](https://en.wikipedia.org/wiki/Interface_description_language) (IDL), che di solito è facile da capire. -In IDL all properties are prepended with their types. For instance, `DOMString`, `boolean` and so on. +Nell'IDL tutte le proprietà sono precedute dai rispettivi tipi. Per esempio `DOMString`, `boolean` e così via. -Here's an excerpt from it, with comments: +Eccone un estratto, con commenti: ```js -// Define HTMLInputElement +// Definisce HTMLInputElement *!* -// The colon ":" means that HTMLInputElement inherits from HTMLElement +// I due punti ":" significano che HTMLInputElement eredita da HTMLElement */!* interface HTMLInputElement: HTMLElement { - // here go properties and methods of elements + // seguono le proprietà ed i metodi degli elementi *!* - // "DOMString" means that the value of a property is a string + // "DOMString" significa che il valore di una proprietà è una stringa */!* attribute DOMString accept; attribute DOMString alt; @@ -102,12 +102,12 @@ interface HTMLInputElement: HTMLElement { attribute DOMString value; *!* - // boolean value property (true/false) + // proprietà con valore booleano (true/false) attribute boolean autofocus; */!* ... *!* - // now the method: "void" means that the method returns no value + // ora un metodo: "void" significa che il metodo non restituisce alcun valore */!* void select(); ... @@ -115,7 +115,7 @@ interface HTMLInputElement: HTMLElement { ``` ```` -## The "nodeType" property +## La proprietà "nodeType" The `nodeType` property provides one more, "old-fashioned" way to get the "type" of a DOM node. From 9c69ccb346dfdbdb4ba1cf3eefc927bd5c44b33c Mon Sep 17 00:00:00 2001 From: Marcello Date: Sun, 14 Mar 2021 23:56:45 +0100 Subject: [PATCH 04/16] Update 2-ui/1-document/05-basic-dom-node-properties/article.md --- 2-ui/1-document/05-basic-dom-node-properties/article.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/2-ui/1-document/05-basic-dom-node-properties/article.md b/2-ui/1-document/05-basic-dom-node-properties/article.md index f5959abc5..fc0cddc33 100644 --- a/2-ui/1-document/05-basic-dom-node-properties/article.md +++ b/2-ui/1-document/05-basic-dom-node-properties/article.md @@ -39,7 +39,7 @@ Esso riceve proprietà e metodi per effetto della sovrapposizione di (elencate i - `Element` -- fornisce i metodi generici propri di un elemento, - `Node` -- fornisce i metodi generici propri di un nodo DOM, - `EventTarget` -- consente il supporto agli eventi (che tratteremo in seguito), -- ...e, infine, esso eredita da `Object`, quindi saranno anche disponibili i metodi di un "oggetto semplice" come `hasOwnProperty`. +- ...e, infine, esso eredita da `Object`, quindi saranno disponibili anche i metodi della classe Object come `hasOwnProperty`. Per conoscere il nome della classe di un nodo DOM, ricordiamoci che un oggetto ha solitamente la proprietà `constructor`. Questa si riferisce al costruttore della classe e il suo nome è `constructor.name`: From 073baa9ce51bfa2bafb50d96738a06b8d0dd6e49 Mon Sep 17 00:00:00 2001 From: Marcello Date: Mon, 15 Mar 2021 16:33:14 +0100 Subject: [PATCH 05/16] Update 2-ui/1-document/05-basic-dom-node-properties/article.md --- .../05-basic-dom-node-properties/article.md | 74 +++++++++---------- 1 file changed, 36 insertions(+), 38 deletions(-) diff --git a/2-ui/1-document/05-basic-dom-node-properties/article.md b/2-ui/1-document/05-basic-dom-node-properties/article.md index fc0cddc33..f9ba1dbef 100644 --- a/2-ui/1-document/05-basic-dom-node-properties/article.md +++ b/2-ui/1-document/05-basic-dom-node-properties/article.md @@ -8,7 +8,7 @@ In questo capitolo vedremo meglio cosa sono e impareremo le loro proprietà più Nodi del DOM differenti possono avere proprietà differenti. Ad esempio, un nodo elemento corrispondente ad un tag `` avrà proprietà tipiche dei link ed un nodo corrispondente al tag `` 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. -Ogni nodo del DOM appartiene alla corrispondente classe integrata. +Ogni nodo del DOM appartiene alla corrispondente classe nativa. 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. @@ -117,89 +117,87 @@ interface HTMLInputElement: HTMLElement { ## La proprietà "nodeType" -The `nodeType` property provides one more, "old-fashioned" way to get the "type" of a DOM node. +La proprietà `nodeType` offre un altro modo "vecchio stile" per ricavare il "tipo" di un nodo DOM. -It has a numeric value: -- `elem.nodeType == 1` for element nodes, -- `elem.nodeType == 3` for text nodes, -- `elem.nodeType == 9` for the document object, -- there are few other values in [the specification](https://dom.spec.whatwg.org/#node). +Ha un valore numerico: +- `elem.nodeType == 1` per i nodi elemento, +- `elem.nodeType == 3` per i nodi testo, +- `elem.nodeType == 9` per l'oggetto documento, +- c'è qualche altro valore nella [specifica](https://dom.spec.whatwg.org/#node). -For instance: +Per esempio: ```html run ``` -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. +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. -## Tag: nodeName and tagName +## Tag: nodeName e tagName -Given a DOM node, we can read its tag name from `nodeName` or `tagName` properties: +Dato un nodo DOM, possiamo leggerne il tag tramite le proprietà `nodeName` o `tagName`: -For instance: +Per esempio: ```js run alert( document.body.nodeName ); // BODY alert( document.body.tagName ); // BODY ``` -Is there any difference between `tagName` and `nodeName`? +Esiste una differenza tra `tagName` e `nodeName`? -Sure, the difference is reflected in their names, but is indeed a bit subtle. +Certamente, i nomi stessi delle proprietà suggeriscono la sottile differenza. -- The `tagName` property exists only for `Element` nodes. -- The `nodeName` is defined for any `Node`: - - for elements it means the same as `tagName`. - - for other node types (text, comment, etc.) it has a string with the node type. +- La proprietà `tagName` esiste solo per i nodi `Element`. +- La proprietà `nodeName` è definita per ogni `Node`: + - per i nodi elemento ha lo stesso valore di `tagName`. + - per gli altri tipi di nodo (testo, commento, ecc.) contiene una stringa che indica il tipo di nodo. -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. - -For instance, let's compare `tagName` and `nodeName` for the `document` and a comment node: +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. +Per esempio paragoniamo `tagName` e `nodeName` per `document` e per un commento: ```html run ``` -If we only deal with elements, then we can use both `tagName` and `nodeName` - there's no difference. +Se abbiamo a che fare solo con elementi allora possiamo usare senza distinzione `tagName` e `nodeName` -```smart header="The tag name is always uppercase except in XML mode" -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`. +```smart header="Il nome del tag è sempre in maiuscolo tranne che nell'XML" +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`. -In HTML mode `tagName/nodeName` is always uppercased: it's `BODY` either for `` or ``. +In modalità HTML `tagName/nodeName` è sempre maiuscola: restituisce `BODY` sia per `` sia per ``. -In XML mode the case is kept "as is". Nowadays XML mode is rarely used. +In modalità XML il case viene mantenuto "così com'è". Ai giorni nostri la modalità XML è usata raramente. ``` +## innerHTML: i contenuti -## innerHTML: the contents - -The [innerHTML](https://w3c.github.io/DOM-Parsing/#the-innerhtml-mixin) property allows to get the HTML inside the element as a string. +La proprietà [innerHTML](https://w3c.github.io/DOM-Parsing/#the-innerhtml-mixin) consente di ottenere una stringa dell'HTML dentro l'elemento. We can also modify it. So it's one of the most powerful ways to change the page. From 6c2614729d6251253a5c1cfb7f626ef7a8837a89 Mon Sep 17 00:00:00 2001 From: Marcello Date: Mon, 15 Mar 2021 16:38:25 +0100 Subject: [PATCH 06/16] Update 2-ui/1-document/05-basic-dom-node-properties/article.md --- 2-ui/1-document/05-basic-dom-node-properties/article.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/2-ui/1-document/05-basic-dom-node-properties/article.md b/2-ui/1-document/05-basic-dom-node-properties/article.md index f9ba1dbef..b1cd3f534 100644 --- a/2-ui/1-document/05-basic-dom-node-properties/article.md +++ b/2-ui/1-document/05-basic-dom-node-properties/article.md @@ -144,7 +144,7 @@ Per esempio: ``` -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. +Nel codice moderno possiamo usare `instanceof` e altri test basati sulle classi per ottenere il tipo di nodo, ma, talvolta, può risultare più immediato l'uso di `nodeType`. La proprietà `nodeType` è in sola lettura, non possiamo modificarla. ## Tag: nodeName e tagName @@ -187,7 +187,7 @@ Per esempio paragoniamo `tagName` e `nodeName` per `document` e per un commento: Se abbiamo a che fare solo con elementi allora possiamo usare senza distinzione `tagName` e `nodeName` -```smart header="Il nome del tag è sempre in maiuscolo tranne che nell'XML" +```smart header="Il nome del tag è sempre in maiuscolo tranne che per l'XML" 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`. In modalità HTML `tagName/nodeName` è sempre maiuscola: restituisce `BODY` sia per `` sia per ``. From 4367598d58898c4cc8578d571bd0e51f541d6ee6 Mon Sep 17 00:00:00 2001 From: Marcello Date: Tue, 16 Mar 2021 23:58:14 +0100 Subject: [PATCH 07/16] Update 2-ui/1-document/05-basic-dom-node-properties/article.md --- .../05-basic-dom-node-properties/article.md | 84 +++++++++---------- 1 file changed, 42 insertions(+), 42 deletions(-) diff --git a/2-ui/1-document/05-basic-dom-node-properties/article.md b/2-ui/1-document/05-basic-dom-node-properties/article.md index b1cd3f534..c8e2b71dd 100644 --- a/2-ui/1-document/05-basic-dom-node-properties/article.md +++ b/2-ui/1-document/05-basic-dom-node-properties/article.md @@ -197,11 +197,11 @@ In modalità XML il case viene mantenuto "così com'è". Ai giorni nostri la mod ## innerHTML: i contenuti -La proprietà [innerHTML](https://w3c.github.io/DOM-Parsing/#the-innerhtml-mixin) consente di ottenere una stringa dell'HTML dentro l'elemento. +La proprietà [innerHTML](https://w3c.github.io/DOM-Parsing/#the-innerhtml-mixin) consente di ottenere una stringa contenente l'HTML dentro l'elemento. -We can also modify it. So it's one of the most powerful ways to change the page. +Possiamo anche modificarla e pertanto è uno dei più potenti strumenti per cambiare la pagina. -The example shows the contents of `document.body` and then replaces it completely: +L'esempio mostra il contenuto di `document.body` e quindi lo rimpiazza completamente: ```html run @@ -209,71 +209,71 @@ The example shows the contents of `document.body` and then replaces it completel
A div
``` -We can try to insert invalid HTML, the browser will fix our errors: +Se proviamo a inserire HTML non valido, il browser correggerà i nostri errori: ```html run ``` -```smart header="Scripts don't execute" -If `innerHTML` inserts a ` ``` -**Beware: unlike `innerHTML`, writing to `outerHTML` does not change the element. Instead, it replaces it in the DOM.** +**Attenzione: diversamente da `innerHTML`, la scrittura in `outerHTML` non cambia l'elemento ma lo sostituisce nel DOM.** -Yeah, sounds strange, and strange it is, that's why we make a separate note about it here. Take a look. +Proprio così, sembra strano, e lo è. Ecco perché ne parliamo subito con una nota a parte. Prestate attenzione. -Consider the example: +Considerate l'esempio: ```html run
Hello, world!
@@ -296,35 +296,35 @@ Consider the example: let div = document.querySelector('div'); *!* - // replace div.outerHTML with

...

+ // sostituisce div.outerHTML con

...

*/!* div.outerHTML = '

A new element

'; // (*) *!* - // Wow! 'div' is still the same! + // Wow! 'div' non è cambiato! */!* alert(div.outerHTML); //
Hello, world!
(**) ``` -Looks really odd, right? +Sembra davvero strano, vero? -In the line `(*)` we replaced `div` with `

A new element

`. In the outer document (the DOM) we can see the new content instead of the `
`. But, as we can see in line `(**)`, the value of the old `div` variable hasn't changed! +Nella linea `(*)` sostituiamo `div` con `

A new element

`. Nel documento (il DOM) possiamo osservare che il nuovo contenuto ha preso il posto di `
`. Tuttavia, come possiamo notare nella linea `(**)`, il precedente valore della variabile `div`non è cambiato! -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. +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. -So what happened in `div.outerHTML=...` is: -- `div` was removed from the document. -- Another piece of HTML `

A new element

` was inserted in its place. -- `div` still has its old value. The new HTML wasn't saved to any variable. +Ricapitolando ciò che è successo in `div.outerHTML=...` è: +- `div` è stato rimosso dal documento. +- Un pezzo di HTML differente `

A new element

` è stato inserito al suo posto. +- `div` mantiene ancora il suo valore precedente. L'HTML inserito in seguito non è stato memorizzato in alcuna variabile. -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`. +È 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`. -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. +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. -## nodeValue/data: text node content +## nodeValue/data: il contenuto testuale del nodo -The `innerHTML` property is only valid for element nodes. +La proprietà `innerHTML` è valida soltanto per i nodi elemento. 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. From 7b5364738dc5dd38862af75af9d801e8c1d1de12 Mon Sep 17 00:00:00 2001 From: Marcello Date: Wed, 17 Mar 2021 01:39:36 +0100 Subject: [PATCH 08/16] Update 2-ui/1-document/05-basic-dom-node-properties/article.md --- .../05-basic-dom-node-properties/article.md | 62 +++++++++---------- 1 file changed, 31 insertions(+), 31 deletions(-) diff --git a/2-ui/1-document/05-basic-dom-node-properties/article.md b/2-ui/1-document/05-basic-dom-node-properties/article.md index c8e2b71dd..f05b61abf 100644 --- a/2-ui/1-document/05-basic-dom-node-properties/article.md +++ b/2-ui/1-document/05-basic-dom-node-properties/article.md @@ -326,9 +326,9 @@ Possiamo scrivere tramite `elem.outerHTML`, ma dovremmo tenere bene presente che La proprietà `innerHTML` è valida soltanto per i nodi elemento. -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. +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. -An example of reading the content of a text node and a comment: +Ecco un esempio di lettura del contenuto di un nodo di testo e di un commento: ```html run height="50" @@ -348,9 +348,9 @@ An example of reading the content of a text node and a comment: ``` -For text nodes we can imagine a reason to read or modify them, but why comments? +Per i nodi di testo possiamo ipotizzare un motivo per leggerne o modificarne il contenuto testuale, ma perché i commenti? -Sometimes developers embed information or template instructions into HTML in them, like this: +Talvolta gli sviluppatori incorporano informazioni o istruzioni sui template nei commenti all'interno dell'HTML, in questo modo: ```html @@ -358,13 +358,13 @@ Sometimes developers embed information or template instructions into HTML in the ``` -...Then JavaScript can read it from `data` property and process embedded instructions. +...così JavaScript può leggerle tramite la proprietà `data` ed elaborare le istruzioni contenute. -## textContent: pure text +## textContent: solo il testo -The `textContent` provides access to the *text* inside the element: only text, minus all ``. +La proprietà `textContent` fornisce l'accesso al *testo* dentro l'elemento: solo il testo, al netto di tutti i ``. -For instance: +Per esempio: ```html run
@@ -378,18 +378,18 @@ For instance: ``` -As we can see, only text is returned, as if all `` were cut out, but the text in them remained. +Come possiamo notare viene restituito solo il testo, come se tutti i `` fossero stati eliminati, ma il testo in essi fosse rimasto. -In practice, reading such text is rarely needed. +Leggere il testo in questa maniera è un'esigenza rara nell'uso pratico. -**Writing to `textContent` is much more useful, because it allows to write text the "safe way".** +**È molto più utile scrivere con `textContent`, perché consente di inserire testo "in sicurezza".** -Let's say we have an arbitrary string, for instance entered by a user, and want to show it. +Supponiamo di avere una stringa arbitraria, ad esempio inserita da un utente, e di volerla mostrare. -- With `innerHTML` we'll have it inserted "as HTML", with all HTML tags. -- With `textContent` we'll have it inserted "as text", all symbols are treated literally. +- Con `innerHTML` la inseriremo "come HTML", compresi tutti i tag HTML. +- Con `textContent` la inseriremo "come testo", tutti i simboli sono trattati letteralmente. -Compare the two: +Paragoniamo le due opzioni: ```html run
@@ -403,16 +403,16 @@ Compare the two: ``` -1. The first `
` gets the name "as HTML": all tags become tags, so we see the bold name. -2. The second `
` gets the name "as text", so we literally see `Winnie-the-Pooh!`. +1. Il primo `
` riceve il nome "come HTML": tutti i tag diventano tali, perciò vedremo il nome in grassetto. +2. Il secondo `
` riceve il nome "come testo", perciò vedremo letteralmente `Winnie-the-Pooh!`. -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. +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. -## The "hidden" property +## La proprietà "hidden" -The "hidden" attribute and the DOM property specifies whether the element is visible or not. +L'attributo "hidden" e la corrispettiva proprietà del DOM specificano se l'elemento debba essere visibile o meno. -We can use it in HTML or assign it using JavaScript, like this: +Possiamo agire da codice HTML o da JavaScript in questo modo: ```html run height="80"
Both divs below are hidden
@@ -426,9 +426,9 @@ We can use it in HTML or assign it using JavaScript, like this: ``` -Technically, `hidden` works the same as `style="display:none"`. But it's shorter to write. +Tecnicamente, `hidden` funziona alla stessa maniera di `style="display:none"` ma è più breve da scrivere. -Here's a blinking element: +Ecco come ottenere un elemento lampeggiante: ```html run height=50 @@ -439,16 +439,16 @@ Here's a blinking element: ``` -## More properties +## Altre proprietà -DOM elements also have additional properties, in particular those that depend on the class: +Gli elementi DOM hanno inoltre proprietà aggiuntive, in particolare quelle che dipendono dalla classe: -- `value` -- the value for ``, `