Inline Scripts

You can listen for livewire:load and place any JavaScript there.

We recommend you use AlpineJS for most of your JavaScript needs, but you can use <script> tags directly inside your Templates.

<div>
    <!--- Your component's template --->
    <script>
        document.addEventListener('livewire:load', function () {
            // Your JS here.
        })
    </script>
</div>

Your scripts will be run only once upon the first render of the component. If you need to run a JavaScript function later, you can emit the Event from the component and listen to it in JavaScript.

Last updated