diff --git a/2-ui/1-document/04-searching-elements-dom/1-find-elements/solution.md b/2-ui/1-document/04-searching-elements-dom/1-find-elements/solution.md index c73aecd99..062bc7c4a 100644 --- a/2-ui/1-document/04-searching-elements-dom/1-find-elements/solution.md +++ b/2-ui/1-document/04-searching-elements-dom/1-find-elements/solution.md @@ -1,35 +1,35 @@ -There are many ways to do it. +Ci sono molti modi per farlo. -Here are some of them: +Eccone alcuni: ```js -// 1. The table with `id="age-table"`. +// 1. La tabella con `id="age-table"`. let table = document.getElementById('age-table') -// 2. All label elements inside that table +// 2. Tutti gli elementi label dentro la tabella table.getElementsByTagName('label') -// or +// oppure document.querySelectorAll('#age-table label') -// 3. The first td in that table (with the word "Age") +// 3. Il primo td dentro la tabella (con la parola "Age") table.rows[0].cells[0] -// or +// oppure table.getElementsByTagName('td')[0] -// or +// oppure table.querySelector('td') -// 4. The form with the name "search" -// assuming there's only one element with name="search" in the document +// 4. La form con il nome "search" +// supponendo ci sia solo un elemento con name="search" nel documento let form = document.getElementsByName('search')[0] -// or, form specifically +// oppure, form specificamente document.querySelector('form[name="search"]') -// 5. The first input in that form. +// 5. Il primo input contenuto in form. form.getElementsByTagName('input')[0] -// or +// oppure form.querySelector('input') -// 6. The last input in that form -let inputs = form.querySelectorAll('input') // find all inputs -inputs[inputs.length-1] // take the last one +// 6. L'ultimo input in form +let inputs = form.querySelectorAll('input') // trova tutti gli input +inputs[inputs.length-1] // prendi l'ultimo ``` diff --git a/2-ui/1-document/04-searching-elements-dom/1-find-elements/task.md b/2-ui/1-document/04-searching-elements-dom/1-find-elements/task.md index f0b54beac..cde00842d 100644 --- a/2-ui/1-document/04-searching-elements-dom/1-find-elements/task.md +++ b/2-ui/1-document/04-searching-elements-dom/1-find-elements/task.md @@ -2,17 +2,17 @@ importance: 4 --- -# Search for elements +# Ricerca degli elementi -Here's the document with the table and form. +Abbiamo un documento con una tabella e un form. -How to find?... +Come trovare?... -1. The table with `id="age-table"`. -2. All `label` elements inside that table (there should be 3 of them). -3. The first `td` in that table (with the word "Age"). -4. The `form` with `name="search"`. -5. The first `input` in that form. -6. The last `input` in that form. +1. La tabella con `id="age-table"`. +2. Tutti gli elementi `label` dentro la tabella (dovrebbero essercene 3). +3. Il primo `td` nella tabella (con la parola "Age"). +4. Il `form` con `name="search"`. +5. Il primo `input` nel form. +6. L'ultimo `input` nel form. -Open the page [table.html](table.html) in a separate window and make use of browser tools for that. +Apri la pagina [table.html](table.html) in un'altra finestra e utilizza gli strumenti del browser. diff --git a/2-ui/1-document/04-searching-elements-dom/article.md b/2-ui/1-document/04-searching-elements-dom/article.md index 5af6435ce..d7f1911df 100644 --- a/2-ui/1-document/04-searching-elements-dom/article.md +++ b/2-ui/1-document/04-searching-elements-dom/article.md @@ -1,14 +1,14 @@ -# Searching: getElement*, querySelector* +# Ricerca: getElement*, querySelector* -DOM navigation properties are great when elements are close to each other. What if they are not? How to get an arbitrary element of the page? +Le proprietà di navigazione del DOM funzionano bene per gli elementi vicini. E quando non lo sono? Come possiamo ottenere un elemento arbitrario della pagina? -There are additional searching methods for that. +Ci sono altri metodi di ricerca per questo. -## document.getElementById or just id +## document.getElementById o semplicemente id -If an element has the `id` attribute, we can get the element using the method `document.getElementById(id)`, no matter where it is. +Se un elemento ha un attributo `id` possiamo trovarlo, ovunque esso sia, utilizzando il metodo `document.getElementById(id)` -For instance: +Ad esempio: ```html run
@@ -16,17 +16,17 @@ For instance:
``` -Also, there's a global variable named by `id` that references the element: +Inoltre, c'è una variabile globale chiamata come l'`id` che fa riferimento all'elemento: ```html run
@@ -34,51 +34,51 @@ Also, there's a global variable named by `id` that references the element:
``` -...That's unless we declare a JavaScript variable with the same name, then it takes precedence: +...Questo a meno di dichiarare una variabile JavaScript con lo stesso nome: quest'ultima avrebbe la precedenza: ```html run untrusted height=0
``` -```warn header="Please don't use id-named global variables to access elements" -This behavior is described [in the specification](http://www.whatwg.org/specs/web-apps/current-work/#dom-window-nameditem), so it's kind of standard. But it is supported mainly for compatibility. +```warn header="Non utilizzate le variabili-id globali per accedere agli elementi" +Questo comportamento è descritto [nella specifica](http://www.whatwg.org/specs/web-apps/current-work/#dom-window-nameditem), quindi è quasi uno standard, ma è supportato principalmente per una questione di compatibilità. -The browser tries to help us by mixing namespaces of JS and DOM. That's fine for simple scripts, inlined into HTML, but generally isn't a good thing. There may be naming conflicts. Also, when one reads JS code and doesn't have HTML in view, it's not obvious where the variable comes from. +Il browser cerca di aiutarci mischiando i namespaces di JS e del DOM. Questo va bene per un semplice script, ma generalmente non è una buona cosa. Potrebbero esserci conflitti tra i nomi. Inoltre, quando uno legge il codice JS e non ha sott'occhio quello HTML non è ovvia la provenienza di una variabile. -Here in the tutorial we use `id` to directly reference an element for brevity, when it's obvious where the element comes from. +Qui nel tutorial, per brevità e quando è ovvia la provenienza dell'elemento, utilizziamo `id` come diretto riferimento ad esso. -In real life `document.getElementById` is the preferred method. +Normalmente `document.getElementById` è il metodo da preferire. ``` -```smart header="The `id` must be unique" -The `id` must be unique. There can be only one element in the document with the given `id`. +```smart header="L'`id` deve essere unico" +Un `id` deve essere unico. Nel documento vi può essere un solo elemento con uno specifico `id`. -If there are multiple elements with the same `id`, then the behavior of methods that use it is unpredictable, e.g. `document.getElementById` may return any of such elements at random. So please stick to the rule and keep `id` unique. +Se ci sono più elementi con lo stesso `id` il comportamento dei metodi che lo utilizzano diventa imprevedibile, ad esempio `document.getElementById` potrebbe ritornare un elemento casuale tra questi. Mantenete gli `id` unici. ``` -```warn header="Only `document.getElementById`, not `anyElem.getElementById`" -The method `getElementById` can be called only on `document` object. It looks for the given `id` in the whole document. +```warn header="Solo `document.getElementById`, non `anyElem.getElementById`" +Il metodo `getElementById` può essere chiamato solo sull'oggetto `document`, cerca l'`id` in tutto il documento. ``` ## querySelectorAll [#querySelectorAll] -By far, the most versatile method, `elem.querySelectorAll(css)` returns all elements inside `elem` matching the given CSS selector. +Tra i metodi più versatili, `elem.querySelectorAll(css)` ritorna tutti gli elementi contenuti in `elem` che combaciano con il selettore CSS specificato. -Here we look for all `
  • ` elements that are last children: +Qui cerchiamo tutti i `
  • ` che sono gli ultimi figli: ```html run