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

403
Vistas
How do I get a button id or value from x-on:click in Alpine JS?

Looking to extract a value or id in Alpine JS onclick, I thought this.id or this.value would work but no luck.

Returns

Alpine Expression Error: Can't find variable: id

<button id="myBtn" value="100" x-on:click="alert(this.id);">Save</button>
about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

This might help you.

<button @click="alert($event.target.getAttribute('message'))" message="Hello World">Say Hi</button>

$event.target will give you access to the clicked element.

Ref: https://alpinejs.dev/directives/on#the-event-object

about 4 years ago · Juan Pablo Isaza Denunciar

0

Pass the Event with $event. Then you can handle it like in vanilaJs.

function hello(e) {
  console.log(e.target.getAttribute('id'))
}
 <script defer src="https://unpkg.com/alpinejs@3.x.x/dist/cdn.min.js"></script>    
<button id="myBtn" value="100" @click="hello($event);">Save</button>

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