Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

iamDiscovery's avatar

Alpine.js: button using @click function not working.

Hi, I'm currently trying to use alpine.js to open a slide out menu utilising x-data="{}", x-show="", and @click="". I've narrowed down the issue to the button I have the @click="" on not actually working. I believe the issue could be that this button is within a different x-show="" element, as I've tried it on a button outside the x-show="" and it's worked. I guess what I'm asking is can you have @click="" functions inside an existing x-show="" element (e.g., a button within a drop down).

0 likes
5 replies
sirch's avatar

Try x-on:click. I had this issue when i had vue installed alongside alpine, there was a conflict of directives

2 likes
iamDiscovery's avatar

I've tried this and it didn't work, I believe it's because it's under another x-data and x-show div. Thanks though.

Snapey's avatar

yes you can nest as long as either you have a nested x-data element or you use a different variable name

1 like
iamDiscovery's avatar

It is in fact within another x-data and x-show component, but even when I give it its own div with its own x-data and put everything inside of that, the element constantly shows as if it's true.

Please or to participate in this conversation.