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

94
Visualizações
Works in the console but not in the editor

I am practicing JavaScript with a program that should change the image of a dice according to a random number. If I put this line in the console the images changes; it works.

document.querySelector("img.img1").setAttribute("src", "images/dice1.png");

but if I put it in the editor I get the following error message:

index.js:5 Uncaught TypeError: Cannot read properties of null (reading 'setAttribute') at index.js:5

Why?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

I forgot differ the link of the js link file in the head. I put this line

<script src="index.js" charset="utf-8"></script>

only in the head of the html file. I should differ it or put it in the end of the body section.

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