Skip to content
Snippets Groups Projects
Commit 06def397 authored by MAHDIR Safaa's avatar MAHDIR Safaa
Browse files

feat : ajouter le filtrage

parent 208cbdee
No related branches found
No related tags found
1 merge request!2Tache2
......@@ -16,6 +16,23 @@ function displayPokemonList() {
listElement.appendChild(listItem);
});
}
// Afficher la liste au chargement de la page
document.addEventListener("DOMContentLoaded", displayPokemonList);
function displayPokemons(list) {
const container = document.getElementById("pokemon-list");
container.innerHTML = "";
list.forEach(pokemon => {
const div = document.createElement("li");
div.textContent = `${pokemon.name} - ${pokemon.weight}kg - ${pokemon.height}m`;
container.appendChild(div);
});
}
// Filtrage
document.getElementById("all").addEventListener("click", () => displayPokemons(pokemons));
document.getElementById("weight").addEventListener("click", () => {
displayPokemons(pokemons.filter(p => p.weight > 3));
});
document.getElementById("height").addEventListener("click", () => {
displayPokemons(pokemons.filter(p => p.height < 1));
});
\ No newline at end of file
body {
font-family: Georgia, sans-serif;
text-align: center;
}
h1 {
color: darkcyan;
}
button {
text-align: center;
background-color: #75a3a3;
border-color: #75a3a3;
color: white;
border-radius: 5px;
}
ul {
list-style-type: none;
padding: 0;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment