Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

84
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda