Check out LiveView’s built-in JS Client Utility Commands, especially JS.show and JS.hide.
Phoenix.LiveView.JS
Provides commands for executing JavaScript utility operations on the client.
JS commands support a variety of utility operations for common client-side needs, such as adding or removing CSS classes, setting or removing tag attributes, showing or hiding content, and transitioning in and out with animations. While these operations can be accomplished via client-side hooks, JS commands are DOM-patch aware, so operations applied by the JS APIs will stick to elements across patches from the server.
In addition to purely client-side utilities, the JS commands include a richpushAPI, for extending the defaultphx-binding pushes with options to customize targets, loading states, and additional payload values.Client Utility Commands
The following utilities are included:
add_class- Add classes to elements, with optional transitionsremove_class- Remove classes from elements, with optional transitionsset_attribute- Set an attribute on elementsremove_attribute- Remove an attribute from elementsshow- Show elements, with optional transitionshide- Hide elements, with optional transitionstoggle- Shows or hides elements based on visibility, with optional transitionstransition- Apply a temporary transition to elements for animationsdispatch- Dispatch a DOM event to elements






















