-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
46 lines (32 loc) · 1.29 KB
/
script.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
45
const pricesMonthly = document.querySelectorAll('[monthly]');
const pricesAnnually = document.querySelectorAll('[annually');
const toggleButton = document.querySelector('.toggle-button');
const toggleButtonControl = document.querySelector('.toggle-button__control');
const annuallyLabel = document.querySelector('.annually-label');
const monthlyLabel = document.querySelector('.monthly-label');
toggleButton.addEventListener('click', () => {
//annually
if (annuallyLabel.classList.contains('inactive')) {
toggleButtonControl.style.right = '32px';
pricesMonthly.forEach(price => {
price.style.display = 'none';
});
pricesAnnually.forEach(price => {
price.style.display = 'block';
});
annuallyLabel.classList.remove('inactive');
annuallyLabel.classList.add('active');
}
// monthly
else if (annuallyLabel.classList.contains('active')) {
toggleButtonControl.style.right = '5px';
pricesAnnually.forEach(price => {
price.style.display = 'none';
});
pricesMonthly.forEach(price => {
price.style.display = 'block';
});
annuallyLabel.classList.add('inactive');
annuallyLabel.classList.remove('active');
}
})