Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to execute multiple statements within a single Alpine.js attribute?

I would like to execute multiple statements within a single Alpine.js event handler (however, I believe it could be generalized to any attribute).

An example of what I would like to achieve:

<button x-data 
        @click="alert('first')" 
        @click="alert('second')">
  Click me
</button>
like image 985
Michal Karbownik Avatar asked Jul 16 '26 00:07

Michal Karbownik


1 Answers

It is possible if you separate statements with a semicolon:

<button x-data 
        @click="alert('first'); alert('second')">
  Click me
</button>
like image 83
Michal Karbownik Avatar answered Jul 17 '26 15:07

Michal Karbownik



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!