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

168
Views
Click event listener working but not keydown?

Why does this work:

buttonGrid.addEventListener('click', e => {
  calculate(e);
});

let calculate = (e) => {
if (e.target.id === "back") {
displayArea.textContent = displayArea.textContent.substring(0, 
   displayArea.textContent.length - 1);
}
}

But not this...

buttonGrid.addEventListener('keydown', e => {
  calculate(e);
});

let calculate = (e) => {
if (e.keyCode === 8) {
displayArea.textContent = displayArea.textContent.substring(0, 
   displayArea.textContent.length - 1);
}
}

See lines 30-45 at: https://jsfiddle.net/s9ebLdvt/2/

If I log out the typeof e.keyCode I get number. Hence I use a number rather than a string.

I've also tried switching the === to == but get the same issue.

Weirdly if I place a console log in the if statement it fires it just doesn't compute the code?

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