-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
42 lines (35 loc) · 1.18 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
var allStar = document.querySelectorAll(".star");
var h3Element = document.querySelector("h3");
let prevClicked;
console.log(allStar);
for(let i=0;i<allStar.length;i++){
allStar[i].addEventListener('click', function(e){
var starClicked = e.target.classList[1];
console.log(starClicked)
for(var j=0;j<allStar.length;j++){
allStar[j].classList.remove("yellow");
}
for(var j=0;j<starClicked;j++){
allStar[j].classList.add("yellow");
}
prevClicked = starClicked;
h3Element.innerText = `Rating : ${starClicked}`;
})
allStar[i].addEventListener('mouseover',function(e){
var starClicked = e.target.classList[1];
for(var j=0;j<prevClicked;j++){
allStar[j].classList.remove("yellow");
}
for(var j=0;j<starClicked;j++){
allStar[j].classList.add("yellow");
}
})
allStar[i].addEventListener('mouseleave',function(e){
for(var j=0;j<allStar.length;j++){
allStar[j].classList.remove("yellow");
}
for(var j=0;j<prevClicked;j++){
allStar[j].classList.add("yellow");
}
})
}