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

89
Visualizações
I have a problem with an onclick and a function

So, for a school project I need to make a website. I am very new to programming but I have had experiences in the past. I was making a tab function that displayed a paragraph with information. For personal reasons I blocked out the info with a -, but this is the part I am having problems with.

Html:

<h1 class="text-center">CSS</h1
<div id="css">
<h2 class="text-center">-</h2>
<p class="text-center">-</p>
</div>
<hr>

Javascript:

//Css toggle
document.getElementById("css").onclick = function() {
if (css1 == 0) {
document.getElementById("css").style.display = "block";
css1 = 1
} else {
document.getElementById("css").style.display = "none";
css1 = 0
} }

The part I am having problems with is in the javascript.

document.getElementById("css").onclick = function() {

In the console it gives an error that says "Uncaught TypeError: Cannot set properties of null (setting 'onclick')"

My question is. What is going wrong?

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