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

188
Views
How to differentiate focus in event from TAB and Shift TAB?

In a DOM where there is multiple focus elements . The user can traverse the focus elements using tab , or traverse reverse by using shift + tab.

Listening on the focusin event how can we know whether it was triggered by TAB or Shift TAB ?

document.querySelector('#sample').addEventListener('focusin', function(){

if(isFromTAB){
 // DO traverse
}else{
  // DO different thing
}


});

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

0

You can check the relatedTarget property of the event. For a focusin event, the relatedTarget property identifies the element that lost focus:

document.querySelector('#b').addEventListener('focusin', (e) => {
  if (e.relatedTarget?.id === 'a') {
    console.log('tab');
  } else if (e.relatedTarget?.id === 'c') {
    console.log('shift tab');
  }
});
<input id="a">
<input id="b">
<input id="c">

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!