forked from MultiverseLearningProducts/Lightbulb-Selectors
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
17 lines (14 loc) · 637 Bytes
/
Copy pathscript.js
File metadata and controls
17 lines (14 loc) · 637 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
// Select the subtitle element and all lightbulbs
let subtitle = document.querySelector(".title");
let lightbulbs = document.querySelectorAll(".lightbulb"); // Get all lightbulbs at once
let count = 0;
// Use a loop to attach event listeners to each lightbulb
lightbulbs.forEach(function(lightbulb) {
lightbulb.addEventListener("click", function() {
// Toggle the "active" class for the clicked lightbulb
lightbulb.classList.toggle("active");
// Increment the click count and update the subtitle
count++;
subtitle.innerHTML = `You've clicked the lights ${count} times.`;
});
});