Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

816
Views
Botón Me gusta con contadores usando html css y jquery

Me gustaría incluir un botón "Me gusta" en un sitio web con un contador. Los botones Me gusta incluyen un recuento del número actual de Me gusta. Si no se hace clic, se muestra el número actual de Me gusta. Cuando se hace clic en un botón, la cantidad actual de clics aumenta en uno (y el estado o la apariencia del botón cambia), y el recuento de Me gusta debe almacenarse en la lógica del lado del servidor para almacenar y servir la cantidad de Me gusta.

¿Es posible lograr esto en HTML, CSS y Jquery?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Utilice este fragmento de código :)

 let likes = 0; $(document).ready(function () { // ajax to get current likes // let likes from server are 10 // assign the current likes to variable likes = 10; setLikes(likes); }); $("body").on("click", ".likeBtn", function () { // ajax to post a current likes // in success add increment to likes likes++; setLikes(likes); }); function setLikes(count) { $(".totalLikes").text(count); }
 <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <meta http-equiv="X-UA-Compatible" content="IE=edge" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <title>Likes Counter</title> </head> <body> <button class="likeBtn"> Like (<span class="totalLikes">0</span>) </button> <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> </body> </html>

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!