@ramstack/alpinegear-destroy provides 'x-destroy' Alpine.js directive, which is the opposite of 'x-init' and allows you to execute code when an element is removed from the DOM.
npm install @ramstack/alpinegear-destroy@ramstack/alpinegear-destroy is a plugin for Alpine.js that provides the x-destroy directive.
This directive is the opposite of x-init and allows you to hook into the cleanup phase of any element in Alpine,
running a callback when the element is removed from the DOM.
tag before the core alpine.js file:``html
`
:`bash
npm install --save @ramstack/alpinegear-destroy
`Then initialize it in your bundle:
`js
import Alpine from "alpinejs";
import destroy from "@ramstack/alpinegear-destroy";Alpine.plugin(destroy);
Alpine.start();
`Usage
In this example, when the is removed, the message Element destroyed will appear.`html
Element destroyed
Hello, World!
``https://github.com/rameel/ramstack.alpinegear.js/tree/main/src/plugins/destroy
You can find the full list of related packages and their documentation here:
https://github.com/rameel/ramstack.alpinegear.js