Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

205
Vistas
Javascript to add or remove classes (hover effect)

Topics, Specialist, Text I have segments that look like little cards with words in them. I would like to unhide a description for the specific word when the user hovers over them.

The code I have is as follows with the concerned classes being "specialist", "specialist-text":

const spec = document.querySelector('.specialist')
const spect = document.querySelector('.specialist-text')

spec.addEventListener('mouseenter', () => spect.classList.remove('hidden'))
.hidden {
  display: none;
}
<section class="topics">
        <h3 class="large center my-1">Topics</h3>
        <div class="width grid overflow">
             <div class="topic-list-update">
                <div class="card2 center btn2 specialist">Specialist</div>
             </div>
             <div class="topics-text">
                <div class="specialist-text hidden">Specialist mathematics 1234</div>
             </div>
        </div>
</section>

And I don't understand why it's not working. I attempted with addEventListener('mouseover'), I have tried using document.getElementById and I tried to use a function instead of an arrow function.

I am receiving an error when launching the html file in firefox:

Uncaught TypeError: spec is null
    <anonymous> http://127.0.0.1:5500/js/script.js:12

I am a complete beginner and I thank you in advance for your help.

about 4 years ago · Santiago Gelvez
1 Respuestas
Responde la pregunta

0

The answer was to load the script at the very end of the body!

<body>
    <div> What ever 1 2 3 4 <br/> 1 2 3 4</div>
    <img>
    <script src="script.js"></script>
</body>
about 4 years ago · Santiago Gelvez Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda