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

187
Views
How to move focus from button to another button

I tried to focus or trigger but it's not working. Please let me know if you have any knowledge. Thanks in advance!

<button onclick="myFunction()">Click</button>
<button id="close-btn">Focus Button</button>


function myFunction() {
   let closeBtn = document.getElementById('close-btn');
       closeBtn.focus();
}
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

This may solve your problem, the css part is just to show the effect.

document.querySelector('#open-btn').addEventListener('click', ()=>{
  document.querySelector('#close-btn').focus()
})
button:focus {
    border: 2px solid rgb(54, 13, 13);
    background-color: aquamarine;
}
<!DOCTYPE HTML>
<html>

<body>
      <button id="open-btn">Click</button>
      <button id="close-btn">Focus Button</button>
</body>

</html>

about 4 years ago · Juan Pablo Isaza Report

0

Try using

function(e) {
    e.preventDefault();
    .....
}

This will prevent the browser's default behavior of any element.

Thanks!

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!