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

219
Visualizações
Uncaught type error in JS, cannot set props of null using innerHTML

I am trying to generate image using specific coordinates on HTML

class Car {
    constructor(id, image, vPosition, wins, hPosition, finishedRace) { //there is a chance I may need to remove the last 3 parms (wins,hpos and finished race)
        this.id = id;
        this.image = image;
        this.vPosition = vPosition;
        this.hPosition = hPosition;
        this.finishedRace = finishedRace;
        this.wins = wins;
    }

Thats my constructor of object car (I am not posting getters and setters since they work fine and are not relevant to my problem)

draw() {
        return "<img id='"+this.id+"' src='"+this.image+"' width='250px' style='position: absolute; left: "+this.hPosition+"px; top: "+this.vPosition+"px;' />";
    }

that is my draw method which I plan to use to draw car objects to HTML

testFunction();

function testFunction() {
    document.getElementById("1").innerHTML = car1.draw();
};

This is test function where I am trying to render the first car object on HTML but that doesn't work (all of this is wrapped under window.onload)

<body>
<h1><b>Race</b></h1>

<p>
    <input id="startRace" type="button" value="Start Race" />
    <input id="resetRace" type="button" value="Reset Race" />
    <input id="viewStats" type="button" value="View Statistics" />
</p>

<div class="1">
   

   
    </div>
    <div class="vl"></div> -->
</div>

Thats my HTML code. The error i get is : Uncaught TypeError: Cannot set properties of null (setting 'innerHTML')

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