Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

194
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda