Skip to content

Commit

Permalink
Add unique ID to "Tous" button in filter
Browse files Browse the repository at this point in the history
  • Loading branch information
Gilles-Lucien committed Dec 27, 2023
1 parent d40ce98 commit 1e762fb
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion FrontEnd/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ async function getCategories() {
// create a unique button "all"
const firstButtonElement = document.createElement("button");
firstButtonElement.innerText = "Tous";
firstButtonElement.id = "all";
firstButtonElement.dataset.id = categories
.map((category) => category.id)
.join(",");
Expand Down Expand Up @@ -68,11 +69,14 @@ async function getCategories() {
// function to handle the click on a filter button
function handleFilterClick(event) {
const categoryId = event.target.dataset.id;
const buttonId = event.target.id;
console.log("Filter button clicked:", categoryId);

const works = document.querySelectorAll(".gallery figure");
works.forEach((work) => {
if (work.dataset.id !== categoryId) {
if (buttonId === "all") {
work.classList.remove("hidden");
} else if (work.dataset.id !== categoryId) {
work.classList.add("hidden");
} else {
work.classList.remove("hidden");
Expand Down

0 comments on commit 1e762fb

Please sign in to comment.