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

310
Views
Setting focus on <button> and making the button show focus (highlighted)

My code is simple:

<html>
<body>
    Test
    <br>
    <button onclick="document.getElementById('btn2').focus();">Button 1</button>
    <br>
    <button id="btn2" onclick="alert('Hello world');">Button 2</button>
</body>
</html>

The question is simple - button one will set focus to button 2. However, the focus is not visible. Only when pressing the Shift key, focus will appear. Focus can also be shown using the tab key, in order to follow focus. I want focus to be visible to the user

My question is how can I set focus and make it visible to the user?

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

0

You can try make it visible to the user by adding css to the page

https://developer.mozilla.org/en-US/docs/Web/CSS/:focus

<style>
#btn2:focus{
   background-color: blueviolet;
}
</style>
about 4 years ago · Juan Pablo Isaza Report

0

is this is what you want?

button:focus{
  outline: 1px solid red
}
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!