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

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

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 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