Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

139
Visualizações
I want to show text in div with javascript

i am trying to make a javascript stopwatch here and i want to add time to div.circle and i don't know whats wrong in this code please help me!! thanks

 <-- this is html 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>stopwatch</title>
 <link rel="stylesheet" href="style.css">
 </head>
 <body>
 <div class="box">
   <h1>Stopwatch</h1>
   <div class="circle"></div>
   <div class="buttons">
    <button>Start</button>
    <button>Stop</button>
    <button>Reset</button>
   </div>
  </div>
 </body>
 <script>  
 <-- this is js code -->   

 let min = 0;
 let sec = 0;
 let mil = 0;

 let time = document.getElementsByClassName("circle");
 time = min + " : " + sec + " : " + mil ;
 time.innerHTML = time;
 console.log (time);

 </script>
 </html>
about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

let time = document.getElementsByClassName("circle");
time = min + " : " + sec + " : " + mil;
time.innerHTML = time;

Those lines actually set the time variable as an element, but then break it and put it inside a string.

Should be like that:

const time = document.getElementsByClassName("circle");
time.innerHTML = min + " : " + sec + " : " + mil;

about 4 years ago · Juan Pablo Isaza Relatório

0

Your code has some very fundamental pieces missing. I have changed it a bit to show something on button click but it will require way more efforts than that. I will highly recommend you to go through some tutorial in HTML, CSS, JS for a day or two.

const button = document.getElementsByTagName("button")[0];
button.onclick=() => {

 let min = 0;
 let sec = 0;
 let mil = 0;

 let time = document.getElementsByClassName("circle")[0];
 let timeString = min + " : " + sec + " : " + mil ;
 time.innerHTML = timeString;
 console.log(timeString);

}
 
 <div class="box">
   <h1>Stopwatch</h1>
   <div class="circle"></div>
   <div class="buttons">
    <button>Start</button>
    <button>Stop</button>
    <button>Reset</button>
   </div>
  </div>
 

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda