Différences
Ci-dessous, les différences entre deux révisions de la page.
| Les deux révisions précédentes Révision précédente Prochaine révision | Révision précédente | ||
| web:jquery:css [2026/03/30 19:31] – [1. Présentation] mno | web:jquery:css [2026/04/01 17:40] (Version actuelle) – [1. Présentation] mno | ||
|---|---|---|---|
| Ligne 3: | Ligne 3: | ||
| ===== JavaScript et jQuery - Sélection et décoration des éléments du DOM ===== | ===== JavaScript et jQuery - Sélection et décoration des éléments du DOM ===== | ||
| - | [Mise à jour le 30/3/2026] | + | [Mise à jour le 1/4/2026] |
| \\ | \\ | ||
| Ligne 12: | Ligne 12: | ||
| \\ | \\ | ||
| + | <callout icon=" | ||
| ==== 1. Présentation ==== | ==== 1. Présentation ==== | ||
| - | La bibliothèque **jQuery**((jQuery- Simplifiez et enrichissez vos développements JavaScript - Pearson - J. Chaffer)) se fonde sur la puissance des [[..: | + | La bibliothèque **jQuery**((jQuery- Simplifiez et enrichissez vos développements JavaScript - Pearson - J. Chaffer)) se fonde sur la puissance des [[..: |
| \\ | \\ | ||
| === 1.1 La fonction $() === | === 1.1 La fonction $() === | ||
| - | <callout type="primary" icon=" | + | <callout type="info" icon=" |
| // | // | ||
| ^ Sélecteur | ^ Sélecteur | ||
| | Nom de balise | | Nom de balise | ||
| - | | Identifiant | + | | Identifiant |
| - | | Classe | + | | Classe |
| \\ | \\ | ||
| === 1.2 La méthode .html de la bibliothèque jQuery === | === 1.2 La méthode .html de la bibliothèque jQuery === | ||
| - | | + | <callout type=" |
| - | <code html5 generic.html> | + | {{ : |
| + | | ||
| + | <code html5 ex1.html> | ||
| <div id=" | <div id=" | ||
| </ | </ | ||
| - | <code javascript | + | <code javascript |
| - | let data = 12; | + | // A placer dans ex1.html |
| - | $("# | + | let data = 12; // création d'une variable data |
| + | | ||
| </ | </ | ||
| Ligne 43: | Ligne 47: | ||
| === 1.3 La méthode .css de la bibliothèque jQuery === | === 1.3 La méthode .css de la bibliothèque jQuery === | ||
| - | <callout type="primary" icon=" | + | <callout type="info" icon=" |
| - | + | {{ : | |
| - | * //Exemple 1// | + | * //Exemple 1 - Changer la couleur d'un texte (compléter ex1.html)// : |
| <code html5 *.html> | <code html5 *.html> | ||
| - | <!-- Fichier | + | <!-- Fichier |
| <div id=" | <div id=" | ||
| </ | </ | ||
| <code javascript *.js> | <code javascript *.js> | ||
| - | // fichier generic.js | ||
| let data = 12; | let data = 12; | ||
| - | | + | $("# |
| + | // A placer dans ex1.html | ||
| $("# | $("# | ||
| </ | </ | ||
| - | * //Exemple 2// | + | * //Exemple 2 - Changer la couleur d'un bloc (à tester dans ex2.html)// : |
| - | <code html5 *.html> | + | {{ : |
| - | <!-- Fichier | + | <code html5 ex2.html> |
| + | <!-- Fichier | ||
| <div id=" | <div id=" | ||
| </ | </ | ||
| <code css *.css> | <code css *.css> | ||
| - | /* fichier generic.css */ | + | /* A placer dans ex2.html */ |
| /* Propriétés graphiques du bloc cel_a */ | /* Propriétés graphiques du bloc cel_a */ | ||
| #cel_a{ | #cel_a{ | ||
| Ligne 77: | Ligne 82: | ||
| <code javascript *.js> | <code javascript *.js> | ||
| - | /* fichier generic.js */ | + | /* A placer dans ex2.html */ |
| | | ||
| $('# | $('# | ||
| - | }); // La couleur du bloc cel_a passe de grey à jaune | + | }); // La couleur du bloc cel_a passe de gris à jaune |
| </ | </ | ||
| Ligne 86: | Ligne 91: | ||
| === 1.4 La méthode .addClass de la bibliothèque jQuery === | === 1.4 La méthode .addClass de la bibliothèque jQuery === | ||
| - | <callout type="primary" icon=" | + | <callout type="info" icon=" |
| - | * //Exemple// | + | * // |
| + | {{ : | ||
| <code html5 *.html> | <code html5 *.html> | ||
| - | <!-- Fichier | + | <!-- Fichier |
| <div id=" | <div id=" | ||
| </ | </ | ||
| <code css *.css> | <code css *.css> | ||
| - | /* fichier generic.css */ | + | /* A placer dans ex3.html */ |
| /* Propriétés graphiques du bloc cel_b */ | /* Propriétés graphiques du bloc cel_b */ | ||
| .cel_b{ /* classe */ | .cel_b{ /* classe */ | ||
| Ligne 107: | Ligne 113: | ||
| <code javascript *.js> | <code javascript *.js> | ||
| - | /* fichier generic.js */ | + | /* A placer dans ex3.html */ |
| $("# | $("# | ||
| </ | </ | ||
| Ligne 113: | Ligne 119: | ||
| \\ | \\ | ||
| - | ==== 2. Changer la couleur d'un bloc | + | ==== 2. Applications |
| - | === 2.1 Changer la couleur d'un bloc en fonction d'un entier N === | + | |
| - | * **Objectif** : changer la couleur d'un bloc en fonction d'un entier. | + | |
| - | | + | === 2.1 Changer la couleur d'un bloc en fonction d'un entier N === |
| + | * **Algorithme partiel proposé** | ||
| < | < | ||
| + | var | ||
| + | N : entier | ||
| + | |||
| + | début | ||
| | | ||
| - | | + | |
| + | | ||
| + | sinon si const0 | ||
| | | ||
| sinon si val1 <= N < val2 | sinon si val1 <= N < val2 | ||
| Ligne 131: | Ligne 142: | ||
| | | ||
| fin si | fin si | ||
| + | fin | ||
| </ | </ | ||
| - | ==== 3. Changer la couleur | + | <callout type=" |
| + | |||
| + | \\ | ||
| + | |||
| + | === 2.1 Changer la couleur | ||
| + | * **Algorithme partiel proposé** | ||
| + | < | ||
| + | Algoithme Changer_Couleur_nN | ||
| + | var | ||
| + | tab = [N0,N1,..., Nn-1, Nn] # liste des valeurs de N | ||
| + | |||
| + | début | ||
| + | Pour i de 0 à n faire | ||
| + | si Tab[i] < const0 alors | ||
| + | changer_couleur_bloci | ||
| + | sinon si const0 <= Tab[i] < const1 alors | ||
| + | changer_couleur_bloci | ||
| + | sinon si const1 <= Tab[i] < const2 | ||
| + | changer_couleur_bloci | ||
| + | ... | ||
| + | ... | ||
| + | sinon si constn-1 <= Tab[i] < constn | ||
| + | changer_couleur_bloci | ||
| + | sinon | ||
| + | changer_couleur_bloci | ||
| + | fin si | ||
| + | fin pour | ||
| + | fin | ||
| + | </ | ||
| + | |||
| + | <callout type=" | ||
| - | ==== 4. Changer la couleur de n bloc en fonction d'un entier N ==== | ||