Skip to content

$event

$event magic can be used to access the native JavaScript event object from an expression in any Alpine component.

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

In addition, Alpine also passes the event object to any methods referenced without trailing parenthesis. For example:

html
<button @click="handleClick">...</button>
 
<script>
    function handleClick(e) {
        // Now you can access the event object (e) directly
    }
</script>