Thanks @skywalker, your answer was the push in the right direction. Two things were different for the solution though: 1) I needed to publish the Livewire pagination component, not the default Laravel one that you mentioned and 2) @click doesn’t work on this Livewire component.
What I did was this:
Publish the Livewire pagination component: php artisan livewire:publish --pagination
Then in resources/views/vendor/livewire
you’ll find the pagination components. I’m using the Bootstrap one.
In this component you’ll find <button>
elements with a wire:click
on them. That’s probably why using AlpineJS’s @click
won’t work here.
I had to fallback to ‘he who shall not be named’ here, please don’t judjge
.
On each button element in the pagination component I added a class called page-link-scroll-to-top
and in my JS I have:
$(document).on('click', '.page-link-scroll-to-top', function (e) {
$("html, body").animate({ scrollTop: 0 }, "slow");
return false;
});
Hope this helps others that want to achieve the same thing. If using both @click
and wire:click
on the button can be done then I’m open to suggestions.