Skip to content

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 or this.value would work but no luck.


Alpine Expression Error: Can’t find variable: id

<button id="myBtn" value="100" x-on:click="alert(;">Save</button>


This might help you.

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

$ will give you access to the clicked element.