Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

404
Views
¿Cómo obtengo una identificación de botón o un valor de x-on: haga clic en Alpine JS?

Buscando extraer un valor o id en Alpine JS al hacer clic, pensé que this.id o this.value funcionaría, pero no tuve suerte.

Devoluciones

Error de expresión alpina: no se puede encontrar la variable: id

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

0

Esto podría ayudarte.

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

$event.target le dará acceso al elemento seleccionado.

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

about 4 years ago · Juan Pablo Isaza Report

0

Pase el evento con $event. Entonces puedes manejarlo como en vanilaJs.

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

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!