Skip to content

Commit

Permalink
feat: Add toggle functionality for ingredients and preparation sectio…
Browse files Browse the repository at this point in the history
…ns and initiate the functionality for the measurements toggle

ATTENTION: The measurements toggle still needs the main algorithm
  • Loading branch information
SaraFreitas02 committed Jan 21, 2025
1 parent e97350d commit 0ea6caa
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions script.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,41 @@ window.onerror = function () {
<p>We're experiencing an issue with loading the page. Please try refreshing or ensure JavaScript is enabled.</p>
</div>`;
};

// Handle toggle buttons
const toggleBtns = Array.from(document.getElementsByClassName("toggle-btn"));

const measurements = Array.from(
document.getElementsByClassName("measurement-span")
);
const ingredients = document.getElementById("ingredients");
const preparation = document.getElementById("preparation");

if (
!ingredients ||
!preparation ||
toggleBtns.length < 1 ||
measurements.length < 1
) {
throw new Error("Missing elements for toggling");
}

// Toggle between ingredients and preparation
toggleBtns[0].addEventListener("click", () => {
if (ingredients.classList.contains("hidden")) {
ingredients.classList.remove("hidden");
preparation.classList.add("hidden");
} else {
ingredients.classList.add("hidden");
preparation.classList.remove("hidden");
}
});

// Toggle between metric and imperial measurements
toggleBtns[1].addEventListener("click", () => {
measurements.forEach((measurement) => {

//algorithm to be implemented

});
});

0 comments on commit 0ea6caa

Please sign in to comment.