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

220
Vistas
Hover effect is not working after calling a function that changes that inner text of target elements

I have a problem: Hover effect is not working after calling a function that changes the inner text of target elements. Basically, after loading the page it's working, but once I click a 'start' button which calls a function to change the content of the divs, hover effect is no longer working. Here is the code:

  <div class="options">
    <div class="option" id="opt1"><div>A: one</div></div>
    <div class="option" id="opt2"><div>B: two</div></div>
    <div class="option" id="opt3"><div>C: three</div></div>
    <div class="option" id="opt4"><div>D: four</div></div>
  </div>
    <button class="button" onclick="loadQuestions()">Start</button>

  .option {
  border: 2px solid blue;
  }

 .option :hover {
  box-shadow: 0 0 0 3px burlywood;
  cursor: pointer;
  }

  const question = document.getElementById('question');
  const opt1 = document.getElementById('opt1');
  const opt2 = document.getElementById('opt2');
  const opt3 = document.getElementById('opt3');
  const opt4 = document.getElementById('opt4');

  function loadQuestions() {
 question.innerText = 'How old are you?';
 opt1.innerText = 'A: 55';
 opt2.innerText = 'B: 52';
 opt3.innerText = 'C: 82';
 opt4.innerText = 'D: 12';
 }
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You don't have a tag with id question so its throwing an error. Checkout following code:

<!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>Document</title>
    <style>
      .option {
        border: 2px solid blue;
      }

      .option:hover {
        box-shadow: 0 0 0 3px burlywood;
        cursor: pointer;
      }
    </style>
  </head>
  <body>
    <div class="options">
      <span id="question" class="question"></span>
      <div class="option" id="opt1"><div>A: one</div></div>
      <div class="option" id="opt2"><div>B: two</div></div>
      <div class="option" id="opt3"><div>C: three</div></div>
      <div class="option" id="opt4"><div>D: four</div></div>
    </div>
    <button class="button" onclick="javascript:loadQuestions()">Start</button>

    <script type="text/javascript">
      const question = document.getElementById("question");
      const opt1 = document.getElementById("opt1");
      const opt2 = document.getElementById("opt2");
      const opt3 = document.getElementById("opt3");
      const opt4 = document.getElementById("opt4");

      const loadQuestions = () => {
        question.innerText = "How old are you?";
        opt1.innerText = "A: 55";
        opt2.innerText = "B: 52";
        opt3.innerText = "C: 82";
        opt4.innerText = "D: 12";
      };
    </script>
    <script src="./index.js" type="text/javascript"></script>
  </body>
</html>

You have to specify a tag with question id.

about 4 years ago · Juan Pablo Isaza 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