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

219
Views
Cómo agregar una clase a la tarjeta y eliminar una vez que se hace clic fuera

Entonces, tengo un par de tarjetas que se clonarán y quiero agregar una clase cuando se hace clic dentro de esas tarjetas y reemplazarla cuando se hace clic afuera y quiero mantener una clase determinada llamada metadatos sin cambios.

mi violín https://jsfiddle.net/abdotamer3/s57jauxw/27/

Mi función de detección:

 $(".card").on("click", function (e) { $(this).removeClass("viewItemInactive"); $(this).addClass("viewItemActive"); }); $(document).on("click", function (e) { if ($(e.target).is(".card") === false) { $(".card").not(".MetaData").each(function() { $(this).removeClass("viewItemActive"); $(this).addClass("viewItemInactive"); }); } });
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Si lo entiendo correctamente, puede agregar estas 2 líneas al hacer clic

 $(".card").removeClass('randomClass'); $(this).addClass('randomClass');

Entonces, esto agregará clase cuando haga clic en una tarjeta, y la eliminará cuando haga clic en otra tarjeta y también la agregará nuevamente a la que hizo clic.

Entonces, el clic sería así:

 $(".card").on("click", function (e) { $(this).removeClass("viewItemInactive"); $(this).addClass("viewItemActive"); $(".card").removeClass('randomClass'); $(this).addClass('randomClass'); });
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!