Like system with javascript only | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

Like system with javascript only

Hello everyone!, I spent almost an entire afternoon trying to do as a likes counter, but that you can only give it once, something like a Boolean, if it is without like and click, it would be equal to like, and otherwise it would be dislike, but I tried everything with the ifs.. and I don't get :'v, someone could give me an example? I'd appreciate it quite a bit, I don't want anything complex, just a "accountant" of likes

16th Sep 2020, 2:27 AM
Sam Vásquez
Sam Vásquez - avatar
3 Answers
+ 2
Ruba Kh oh.. of course.., since I didn't think of it with toggle, I'll try it, thanks over there helps
16th Sep 2020, 2:54 AM
Sam Vásquez
Sam Vásquez - avatar
+ 1
something like this? <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <link rel='stylesheet' href='https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css'> <title>Like</title> </head> <body> <div style="position: absolute; top:50%; left:50%; transform: translate(-50%, -50%);"> <i id='heart' class="fa fa-heart" style='font-size: 100px; color:red;'></i> </div> </body> <script> var heart = document.getElementById('heart') heart.addEventListener("click", toggleHeart); function toggleHeart() { this.classList.toggle('fa-heart'); this.classList.toggle('fa-heart-o'); } </script> </html>
16th Sep 2020, 2:53 AM
Ruba Kh
Ruba Kh - avatar
+ 1
Las etiquetas me dan risa xd
24th Apr 2021, 1:01 AM
Misael Meriles
Misael Meriles - avatar