Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

190
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda