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

194
Views
How do I attach an access key to a HTML element

I tried to use accesskey attribute but it requires user to use combinations of keys but I want to use a single key to access the element. I tried to search it on web I couldn't find any thing.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You can do that with the help of Javascript but you really shouldn't as the accesskeys natively available require a modifier for very good reasons.

Please note that this effectively disallows to use the keys assigned to accesskeys to be used for anything other than accessing those elements (e.g. you can no longer type those letters in an input), which is why this is not an acceptable solution.

I'm just showing it to demonstrate the general technical approach.

document.addEventListener('keypress', function(event) {
  const target = document.querySelector(`[data-accesskey=${event.key.toLowerCase()}]`);
  if (target) {
    target.focus();
    event.preventDefault();
  }
})
<input type="text" data-accesskey="n" placeholder="Press n to focus this field" />
<button type="button" data-accesskey="p">Press p to focus this button</button>

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!