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

196
Vistas
why 'onfocus' does not work on multiple select option, and 'onclick' does?

I do not see why onfocus='myFunction()' works in a an input, but not in an option, for example:

<input type="text" id="fname" onfocus="myFunction()">

calls myFunction when you click on it or when you tab into it, but:

<select multiple>
<option onfocus="myFunction()">whatever</option>
</select>

Does not work when you step in the option.

Why is this? I cannot find a documentation which says what events work on what elements. I have seen this for a long time, but now I want to know why

EDIT: I am using Chrome.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Please look at the MDM web docs

For onfocus to fire on non-input elements, they must be given the tabindex attribute

So in other terms: give the option with the focus event a tabIndex! The example below should work.

function myFunction() {
      console.log("focus");
}

function myFunction2() {
      console.log("focus2");
}
<select multiple>
    <option tabIndex="0" onfocus="myFunction()">whatever</option>
    <option tabIndex="0" onfocus="myFunction2()">whatever2</option>
</select>

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