-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
44 lines (38 loc) · 1.36 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
document.addEventListener("DOMContentLoaded", function () {
// setting a global state (for managing toggle states)
let currentPriceState = "annual";
// Selecting all Annual prices
const annualPrices = document.querySelectorAll(".price.annually");
// Selecting all monthly prices
const monthlyPrices = document.querySelectorAll(".price.monthly");
// Selecting toggler element
const toggle = document.querySelector(".slider.round");
toggle.addEventListener("click", function () {
if (currentPriceState == "annual") {
/* ============ display monthly info ============= */
// hiding annual prices
annualPrices.forEach((priceElem) => {
priceElem.classList.add("d-none");
});
// showing monthly prices
monthlyPrices.forEach((priceElem) => {
priceElem.classList.remove("d-none");
});
// setting state to monthly
currentPriceState = "monthly";
} else {
// else switch back to annual info
/* ============ display annual info ============= */
// hiding monthly prices
monthlyPrices.forEach((priceElem) => {
priceElem.classList.add("d-none");
});
// showing annual prices
annualPrices.forEach((priceElem) => {
priceElem.classList.remove("d-none");
});
// setting state to annual
currentPriceState = "annual";
}
});
});