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

193
Vistas
Code stops working when I add a function call but works when I remove the call

This code works. It changes the button color without any problem


   document.addEventListener("keypress", function(event) {
        if (event.keyCode == 49) {
     

      button1.style.backgroundColor = "lightgreen";
     
      setTimeout(() => {
       button2.style.border = "";
       button1.style.backgroundColor = "";
          
          console.log("changed style ")

      }, 100);
      getDate();
   }

But when I add socket.Emit("hello","world") It throws the error "getting TypeError: Cannot read properties of null (reading 'style')" it can no longer change the color of button1.


  document.addEventListener("keypress", function(event) {
        if (event.keyCode == 49) {
      socket.emit("hello" , "world") <= When this is added

      button1.style.backgroundColor = "lightgreen"; <= Error is caused by this line
     
      setTimeout(() => {
       button2.style.border = "";
       button1.style.backgroundColor = "";
          
          console.log("changed style ")

      }, 100);
      getDate();
   }
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Button1 is not being defined thus it cannot apply a style to it. Please provide more code or look back and properly define it.

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