Este código funciona. Cambia el color del botón sin ningún problema.
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(); }Pero cuando agrego socket. Emit ("hola", "mundo") arroja el error " obteniendo TypeError: no se pueden leer las propiedades de nulo (leyendo 'estilo') " ya no puede cambiar el color del botón1.
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(); }Button1 no se está definiendo, por lo que no puede aplicarle un estilo. Proporcione más código o mire hacia atrás y defínalo correctamente.