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

279
Visualizações
How to make movement of select options circular?

Consider the following select element. Try to move navigate through the options using arrow keys. You see when you reach the bottom you can't move to top if you press down once more. And same for the top.

<select>
  <option value="A">A</option>
  <option value="B">B</option>
  <option value="C">C</option>
  <option value="D">D</option>
</select>

I want to have this feature with select. But the issue is that I am unable to find out anyway get the option which is temporarily selected while navigating.

One thing I found out is to change the selectedIndex of the element but this also doesn't work because it doesn't change the current hovered/active option of select rather it changes actual value of select.

I have a restriction that I have to use only simple select element of html.

I will be thankful if you are able to help me out.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

let $1 = document.querySelector('#s1')
let $2 = document.querySelector('#s2')
console.log('S1 VALUE:', $1.value, '\nS2 VALUE:', $2.value)
<!-- DEFAULT -->

<select id="s1">
  <option value="A">A</option>
  <option value="B">B</option>
  <option value="C">C</option>
  <option value="D">D</option>
</select><br>

<!-- PRE-SELECTED -->

<select id="s2">
  <option value="A">A</option>
  <option value="B">B</option>
  <option selected value="C">C</option>
  <option value="D">D</option>
</select>

There is a screenshot of my result:

If that solution doesn't work, you can try this:

console.log(document.querySelector('select').selectedOptions[0].value)
<select>
  <option value="A">A</option>
  <option value="B">B</option>
  <option value="C">C</option>
  <option value="D">D</option>
</select>

In that snippet I used: selectedOptions, in options array I choose first object because in <select> element we can choose only single option, so then I get itself value.

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