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

188
Visualizações
JS cannot read proprieties of null "innerHTML" on onload call

I have a function that will display content of item prices which can have their order changed from ascending to descending from the click of a button as well as the buttons innerHTML being changed to display text showing what order they are being displayed in. The onload function is called at the top of my HTML code. There is a check inside my function to see in innerHTML of the button (so it changes to the opposite value each time it is clicked) but when i call the function on onload it appears in console as

'Cannot read properties of null (reading 'innerHTML') at ....... at HTMLScriptElement.onload'

JS function:

function myFunc() {
    var elem = document.getElementById("selectionButton")
    if (elem.innerHTML=="descending") { elem.innerHTML = "ascending "}
    else { elem.innerHTML = "descending"}

Onload:

<script src="script.js" onload="myFunc()" ></script>

Buttons:

<button onclick="myFunc()" id="selectionButton" >Ascending</button>
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