forked from vedant-0408/Restaurant_ITW1
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
15 lines (14 loc) · 691 Bytes
/
Copy pathscript.js
File metadata and controls
15 lines (14 loc) · 691 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
// Select all elements with the "i" tag and store them in a NodeList called "stars"
const stars = document.querySelectorAll(".stars i");
// Loop through the "stars" NodeList
stars.forEach((star, index1) => {
// Add an event listener that runs a function when the "click" event is triggered
star.addEventListener("click", () => {
// Loop through the "stars" NodeList Again
stars.forEach((star, index2) => {
// Add the "active" class to the clicked star and any stars with a lower index
// and remove the "active" class from any stars with a higher index
index1 >= index2 ? star.classList.add("active") : star.classList.remove("active");
});
});
});