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

96
Views
Event handling function

In the task, you need to change the background colour of the block to green when you press the G key, but no changes are made.

<body>
<div id="colorOutput">
</div>

<script>
   let div = document.querySelector("#colorOutput");
   document.addEventListener("keydown", function (event) {
        if (event.code == "Enter") changeToGreen();
    })
   function changeToGreen() {
       div.style.backgroundСolor = "green";
   }
</script>
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Try using the below JS code.

const div = document.getElementById("colorOutput");
window.addEventListener("keydown", (e)=>{
    e.code === "Enter" ? changeToGreen() : null;
});
function changeToGreen() {
       alert("JAI HARI");
       div.style.backgroundСolor = "green";
   }

Use window instead of document for Event Listener.

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!