-
Notifications
You must be signed in to change notification settings - Fork 0
/
alltripreviews.js
37 lines (27 loc) · 1.16 KB
/
alltripreviews.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
let commentButton = document.querySelectorAll(".comment-button");
let commentsList = document.querySelectorAll(".comments-list");
let commentInput = document.querySelectorAll(".comment-input");
let submitButton = document.querySelector("#submit-button");
let errorP = document.querySelector("#error-message");
/*ITERATING OVER THE CLASSES OF THE COMMENTS AND COMMENT INPUT OF EACH POST AND LISTENING FOR COMMENT
ON EACH ONE OF THEM*/
for (let i = 0; i < commentButton.length; i++) {
commentButton[i].addEventListener("click", function () {
//switching on each click
if (commentsList[i].style.display == "none") {
commentsList[i].style.display = "block";
commentInput[i].style.display = "block";
}
else {
commentsList[i].style.display = "none";
commentInput[i].style.display = "none";
}
});
}
submitButton.addEventListener("click", function (eventObj) {
let comment = document.querySelector("#comment").value;
if (!comment) {
eventObj.preventDefault();
errorP.innerText = "You Can't Leave This Field Empty";
}
});