myForEach : sujet A
myMap : sujet B
myFilter : sujet C
myForEach(notes, (n, i, t) => n < 7 && (t[i] = "AJ"));
📒 Selecteur = p
See the Pen UsetherightSelector by dupont (@dupontcodepen) on CodePen.
See the Pen
querySelector by dupont (@dupontcodepen)
on CodePen
Fonctions de base à tester dans la console de http://dupontcours.free.fr/JavaScript/DOM-javascript/dom.html
🆒Sélectionnez tous les paragraphes
Comptez le nombre de paragraphes
Une boucle sur la selection des paragraphes
1️⃣Ajouter une classe à tous les paragraphes
🪛Ajoutez un événement click (voir amélioration par délégation)
🥇La délégation
Parcours à la recherche de texte !
Parcours du DOM
Dans un groupe, il y a des étudiants [👩🏼🦰👦🏿👨🦱👨🏽🦳👩🏽🧔🏽 👩🏽 ]avec chacun une moyenne.
Comment écrire que l'on recherche s'il existe un.E étudiant.e abscent (ABI)
→ Réponse mySome(students, isABI);
Dans un panier (basket) 🧺, il y a plein de fruits et des légumes 🍍🍑 🥕🍅🥦🍒🍌🥔🍄🍓🧄🌰🫛.
Comment écrire que l'on recherche s'il existe un fruit sans pépin (seed) ?
const hasSeedlessFruit = mySome(basket, isSeedlessFruit);
---------------------------------------------
🥷🏿Parcours l'arbre du DOM
| <body> |
<p class="premier">Para 1</p> |
<p><em>second </em> Para 2</p> |
<p id="dernier"> dernier Para</p> |
<!-- je suis un commentaire --> |
| </body> |
https://dupontdenis.github.io/parcoursArbreGenerator/
code :
function* search(node) { console.log("➡️ Entrée dans search() avec :", node); if (!node) { console.log("⛔ Node est null, on stoppe ici."); return; } console.log("📤 Yield du node :", node); yield node; console.log("🔽 Appel récursif sur firstChild :", node.firstChild); yield* search(node.firstChild); console.log("➡️ Appel récursif sur nextSibling :", node.nextSibling); yield* search(node.nextSibling); } // document.body.insertAdjacentHTML("beforeend", `<h1> the DOM`); const nodes = []; for (let node of search(document.body)) { console.log("📥 Node reçu dans le for...of :", node); if (node.localName) nodes.push(node.localName); } document.body.insertAdjacentHTML( "beforeend", `<p>${nodes.join("<span> </span>")}</p>` );
| Property / Method | Description |
|---|---|
| element.appendChild() | Adds a new child node, to an element, as the last child node |
| element.attributes | Returns a NamedNodeMap of an element's attributes |
| element.childElementCount | Returns the number of child elements an element has |
| element.childNodes | Returns a collection of an element's child nodes (including text and comment nodes) |
| element.children | Returns a collection of an element's child element (excluding text and comment nodes) |
| element.classList | Returns the class name(s) of an element |
| element.className | Sets or returns the value of the class attribute of an element |
| element.cloneNode() | Clones an element |
| element.contains() | Returns true if a node is a descendant of a node, otherwise false |
| element.contentEditable | Sets or returns whether the content of an element is editable or not |
| element.firstChild | Returns the first child node of an element |
| element.firstElementChild | Returns the first child element of an element |
| element.getAttribute() | Returns the specified attribute value of an element node |
| element.getAttributeNode() | Returns the specified attribute node |
| element.getElementsByClassName() | Returns a collection of all child elements with the specified class name |
| element.getElementsByTagName() | Returns a collection of all child elements with the specified tag name |
| element.hasChildNodes() | Returns true if an element has any child nodes, otherwise false |
| element.id | Sets or returns the value of the id attribute of an element |
| element.innerHTML | Sets or returns the content of an element |
| element.insertBefore() | Inserts a new child node before a specified, existing, child node |
| element.lastChild | Returns the last child node of an element |
| element.lastElementChild | Returns the last child element of an element |
| element.nextSibling | Returns the next node at the same node tree level |
| element.nextElementSibling | Returns the next element at the same node tree level |
| element.nodeName | Returns the name of a node |
| element.nodeType | Returns the node type of a node |
| element.nodeValue | Sets or returns the value of a node |
| element.parentNode | Returns the parent node of an element |
| element.parentElement | Returns the parent element node of an element |
| element.previousSibling | Returns the previous node at the same node tree level |
| element.previousElementSibling | Returns the previous element at the same node tree level |
| element.querySelector() | Returns the first child element that matches a specified CSS selector(s) of an element |
| element.querySelectorAll() | Returns all child elements that matches a specified CSS selector(s) of an element |
| element.removeAttribute() | Removes a specified attribute from an element |
| element.removeChild() | Removes a child node from an element |
| element.replaceChild() | Replaces a child node in an element |
| element.setAttribute() | Sets or changes the specified attribute, to the specified value |
| element.setAttributeNode() | Sets or changes the specified attribute node |
| element.style | Sets or returns the value of the style attribute of an element |
| element.tagName | Returns the tag name of an element |
| element.textContent | Sets or returns the textual content of a node and its descendants |
| nodelist.item() | Returns the node at the specified index in a NodeList |
| nodelist.length | Returns the number of nodes in a NodeList |
Il est facile de trouver comment rendre 33€ en utilisant des pièces de 5,3 et 1.
En effet, il suffit de décomposer 33 sous la forme [ 33 = 5x + 2y + 1z ].