-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
44 lines (34 loc) · 1.01 KB
/
index.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
const star=document.querySelectorAll(".star");
const container=document.getElementById("container-star");
let filled=0;
//when click on start
container.addEventListener("click",(e)=>{
let currClick=e.target.dataset.index;
for(let i=0;i<filled;i++){
star[i].classList.remove("star-filled")
}
for(let i=0;i<currClick;i++){
star[i].classList.add("star-filled")
}
document.getElementById("count").innerText=`Rating Count: ${currClick}`
filled=currClick;
})
//when hover over star
container.addEventListener("mouseover",(e)=>{
let currClick=e.target.dataset.index;
for(let i=0;i<5;i++){
star[i].classList.remove("star-filled")
}
for(let i=0;i<currClick;i++){
star[i].classList.add("star-filled")
}
})
//after leaving the hover
container.addEventListener("mouseleave",()=>{
for(let i=0;i<5;i++){
star[i].classList.remove("star-filled")
}
for(let i=0;i<filled;i++){
star[i].classList.add("star-filled")
}
})