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

385
Visualizações
Why is it that when I resize my select the first element becomes selected?

If the size of a <select> tag is dynamically changed from JavaScript, the first element becomes automatically selected if the initial size attribute was either 0 or 1 (MSEdge, Win10).

<select id="s" size="1">
  <option>a
  <option>b
  <option>c
</select>

<select size="3">
  <option>a
  <option>b
  <option>c
</select>

<script>
s.size=3;
</script>

I imagine a size of 0 or 1 forces a selection, but I can't see why this is, as I didn't ask it to.

Does anyone have an explanation?

about 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

This is actually covered in the specification:

If nodes are inserted or nodes are removed causing the list of options to gain or lose one or more option elements, or if an option element in the list of options asks for a reset, then, if the select element's multiple attribute is absent, the user agent must run the first applicable set of steps from the following list:

  • If the select element's display size is 1, and no option elements in the select element's list of options have their selectedness set to true
    • Set the selectedness of the first option element in the list of options in tree order that is not disabled, if any, to true.
  • If two or more option elements in the select element's list of options have their selectedness set to true
    • Set the selectedness of all but the last option element with its selectedness set to true in the list of options in tree order to false.
about 4 years ago · Santiago Trujillo 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