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

211
Views
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 answers
Answer question

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 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!