-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvanilla.html
73 lines (61 loc) · 2.11 KB
/
vanilla.html
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="stylesheet" type="text/css" href="../src/style.css" />
<title>VANILLA JS STEPS</title>
</head>
<body>
<div class="steps">
<div class="numbers">
<div class="step-1">1</div>
<div class="step-2">2</div>
<div class="step-3">3</div>
</div>
<p class="message"></p>
<div class="buttons">
<button class="previous">Previous</button>
<button class="next">Next</button>
</div>
</div>
<script>
const messages = [
"Learn React js ⚛️",
"Apply for jobs 💼",
"Invest your new income 🤑",
];
// Selecting DOM elements
const step1 = document.querySelector(".step-1");
const step2 = document.querySelector(".step-2");
const step3 = document.querySelector(".step-3");
const message = document.querySelector(".message");
const btnPrevious = document.querySelector(".previous");
const btnNext = document.querySelector(".next");
// "State"
let step = 1;
// Manually updating the DOM: changing text content and adding/removing classes (imperative approach)
const updateUIValues = function () {
message.textContent = `Step ${step}: ${messages[step - 1]}`;
if (step >= 1) step1.classList.add("active");
else step1.classList.remove("active");
if (step >= 2) step2.classList.add("active");
else step2.classList.remove("active");
if (step >= 3) step3.classList.add("active");
else step3.classList.remove("active");
};
// Initial setup
updateUIValues();
// Manually attaching event listeners
btnPrevious.addEventListener("click", function () {
if (step > 1) step -= 1;
updateUIValues();
});
btnNext.addEventListener("click", function () {
if (step < 3) step += 1;
updateUIValues();
});
</script>
</body>
</html>