forked from Dezenix/frontend-html-css-js
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathscript.js
40 lines (37 loc) · 1.2 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
const ratings = document.querySelectorAll(".rating");
const ratingsContainer = document.querySelector(".ratings-container");
const sendBtn = document.querySelector("#send");
const panel = document.querySelector("#panel");
let selectedRating = "Satisfied";
ratingsContainer.addEventListener("click", (e) => {
if (
e.target.parentNode.classList.contains("rating") &&
e.target.nextElementSibling
) {
removeActive();
e.target.parentNode.classList.add("rating");
selectedRating = e.target.nextElementSibling.innerHTML;
} else if (
e.target.parentNode.classList.contains("rating") &&
e.target.previousSibling &&
e.target.previousElementSibling.nodeName === "IMG"
) {
removeActive();
e.target.parentNode.classList.add("active");
selectedRating = e.target.innerHTML;
}
});
sendBtn.addEventListener("click", (e) => {
panel.innerHTML = `
<i class="fas fa-heart"></i>
<strong>Thank You!</strong>
<br>
<strong>Feedback: ${selectedRating}</strong>
<p>We'll use your feedback to improve our customer support</p>
`;
});
function removeActive() {
for (i = 0; i < ratings.length; i++) {
ratings[i].classList.remove("active");
}
}