Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR HTML

alpine extract data to script tag

<div x-data="dropdown">
    <button @click="toggle">Toggle Content</button>
 
    <div x-show="open">
        Content...
    </div>
</div>
 
<script>
    document.addEventListener('alpine:init', () => {
        Alpine.data('dropdown', () => ({
            open: false,
 
            toggle() {
                this.open = ! this.open
            },
        }))
    })
</script>
Source by alpinejs.dev #
 
PREVIOUS NEXT
Tagged: #alpine #extract #data #script #tag
ADD COMMENT
Topic
Name
5+2 =