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

330
Views
addEventListener no funciona? No funcionó solo cuando ocurrió el evento.

Quería agregar una nueva clase (". when-hover") a algunos elementos HTML (vitrinas) cuando me movía sobre ellos. Así que escribí JS así:

 const beforeHover = document.getElementsByClassName("before-hover"); const showcases = document.getElementsByClassName("project-tile"); for (let showcase of showcases) { showcase.addEventListener("mouseover", addClass("when-hover")); } function addClass(newClass) { for (let el of beforeHover) { el.classList.add(newClass); } }

Pero cuando lo probé, la nueva clase (".when-hover") se agregó a los elementos desde el momento en que abrí la página. Pero quería que la nueva clase se agregara solo al pasar el mouse sobre ella. ¿Qué salió mal con mi código?

Aquí está mi código HTML:

 <a href="#"> <div class="project-tile"> <div class="project-showcase"> <img class="project-img" src="https://cdn.freecodecamp.org/testable-projects-fcc/images/tribute.jpg" alt="Overview image of project name Tribute Page"> </div> <div class="project-name"> <p><span class="before-hover">&#60;</span>Tribute Page<span class="before-hover">&#47;&#62;</span></p> </div> </div> </a>
about 4 years ago · Juan Pablo Isaza
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!