Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

191
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!