Reputation: 4515
I want this element to self hide once clicked. How do I target self with Alpine, and string 2 @click events together?
<div @click="tagify.addTags(['hardware'])">hardware</div>
Upvotes: 1
Views: 4193
Reputation: 1712
This works great for me
<button @click="open = true; event.target.style.display='none';" x-text="'Show more'"></button>
Upvotes: 0
Reputation: 1030
There are multiple ways you can handle this,
you can target self by the event.target
as in method 1
, other methods a just alternative approaches to hide the element.
Method 1 - Set the style inline in the click handler
<div @click="tagify.addTags(['hardware']); event.target.style.display='none';">hardware</div>
Method 2 - Use x-ref
<div x-ref="hardware" @click="tagify.addTags(['hardware']); $refs.hardware.style.display='none';">hardware</div>
Method 3 - Use x-show
with a variable
<div x-data="{showHardware : true}">
....
<div x-show="showHardware" @click="tagify.addTags(['hardware']); showHardware = false">hardware</div>
</div>
Upvotes: 1