-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bbd272f
commit 904fb7d
Showing
3 changed files
with
58 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// Sélectionnez tous les éléments <a> qui contiennent des éléments <p> avec la classe.number | ||
var anchorElements = document.querySelectorAll('a'); | ||
|
||
// Sélectionnez l'élément input | ||
var inputField = document.querySelector('input[type="text"]'); | ||
|
||
// Parcourez chaque élément <a> et ajoutez un écouteur d'événements click | ||
anchorElements.forEach(function(anchor) { | ||
anchor.addEventListener('click', function(e) { | ||
// Empêchez l'action par défaut du lien (si nécessaire) | ||
e.preventDefault(); | ||
|
||
// Trouvez le premier <p> enfant avec la classe.number à l'intérieur de l'élément <a> cliqué | ||
var numberParagraph = this.querySelector('.number'); | ||
if (numberParagraph) { // Vérifie si un élément.number existe | ||
var numberText = numberParagraph.textContent; // Obtenez le texte de l'élément.number | ||
|
||
// Ajoutez le texte à l'élément input | ||
inputField.value += numberText; | ||
} | ||
}); | ||
}); | ||
|
||
document.querySelector('input[type="text"]').addEventListener('input', function() { | ||
if (this.value.length > 16) { | ||
this.value = this.value.substring(0, 16); // Tronque le texte à 16 caractères | ||
} | ||
}); | ||
|
||
|
||
|
||
// Sélectionnez toutes les images dont l'attribut alt est "effacer" | ||
var deleteImages = document.querySelectorAll('img[alt="Effacer"]'); | ||
|
||
// Sélectionnez l'élément input | ||
var inputField = document.querySelector('input[type="text"]'); | ||
|
||
// Parcourez chaque image et ajoutez un écouteur d'événements click | ||
deleteImages.forEach(function(image) { | ||
image.addEventListener('click', function(e) { | ||
// Empêchez l'action par défaut du lien (si nécessaire) | ||
e.preventDefault(); | ||
|
||
// Retirez un caractère de l'élément input | ||
if (inputField.value.length > 0) { | ||
inputField.value = inputField.value.slice(0, -1); | ||
} | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters