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

brandymedia's avatar

Livewire breaking JavaScript event listeners

I have a data table that is filtered via Livewire. Each row has a dropdown button that is controlled via JS.

Unfortunately once Livewire filters the page all the event listeners on the buttons break.

I've tried hooking into events, rewriting the JS but can not for the life of me get the buttons to work.

Has any one else had issues with event listeners and how do you overcome this?

This is a follow up relating to https://laracasts.com/discuss/channels/livewire/livewire-breaking-other-javascript-on-page but more specifically to do with event listeners.

0 likes
1 reply
MohamedTammam's avatar

As I answered the previous thread and the code I provided.

That mostly because when you sort, the element gets deleted from the DOM. Thus, all event attached to it will be removed. Generally, in such a case you should listen to the click event on the document element or any parent that doesn't get removed when sorting.

That might help if my explanation isn't good enough: https://stackoverflow.com/questions/34896106/attach-event-to-dynamic-elements-in-javascript

Please or to participate in this conversation.