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

96
Vistas
AlpineJS: which x-on directive to use inside <option> tag? @click does not seem to work on <option> tag

I'd like to trigger an action when a specific option is selected in select tag. @click works on every other tags, but when it doesn't seem to work on option. Is there a directive like @selected where I can trigger an action when an option is selected?

<html>
  <head>
    <script defer src="https://unpkg.com/alpinejs@3.3.4/dist/cdn.min.js"></script>
  </head>

  <body>

    <div x-data="{}">

        <!-- this does NOT work -->
        <select>
            <option @click="alert('option 1');">option 1</option>
            <option @click="alert('option 2');">option 2</option>
            <option @click="alert('option 3');">option 3</option>
        </select>

        <!-- this works -->
        <button @click="alert('button clicked');">Click</button>

    </div>

  </body>
</html>
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You can't attach events to <option> tags, but you can attach a change event to the <select> tag and use the value of the selected option.

<select x-on:change="alert($el.value)">
    <option>option 1</option>
    <option>option 2</option>
    <option>option 3</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