-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdocument.addEventListener('DOMContentLoa
More file actions
28 lines (22 loc) · 1.12 KB
/
document.addEventListener('DOMContentLoa
File metadata and controls
28 lines (22 loc) · 1.12 KB
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
document.addEventListener('DOMContentLoaded', function () {
const likeButtons = document.querySelectorAll('.like-btn');
const commentButtons = document.querySelectorAll('.comment-btn');
likeButtons.forEach(button => {
button.addEventListener('click', function () {
const post = this.closest('.post');
const likes = post.querySelector('.likes');
let currentLikes = parseInt(likes.innerText, 10);
currentLikes += 1;
likes.innerText = currentLikes === 1 ? `${currentLikes} Curtida` : `${currentLikes} Curtidas`;
});
});
commentButtons.forEach(button => {
button.addEventListener('click', function () {
const post = this.closest('.post');
const comments = post.querySelector('.comments');
let currentComments = parseInt(comments.innerText, 10);
currentComments += 1;
comments.innerText = currentComments === 1 ? `${currentComments} Comentário` : `${currentComments} Comentários`;
});
});
});