Tailwind CSS Remove Element Plugin API
Headless, unstyled remove element plugin built with JavaScript and TypeScript, including installation, usage, options, methods, events, and selectors.
Installation
To get started, install Remove Element plugin via npm, else you can skip this step if you are already using Preline UI as a package.
-
Install the plugin
Install
@preline/remove-elementvia npmTerminalnpm i @preline/remove-element -
Add the plugin CSS
Use @source to register the plugin's JavaScript path for Tailwind CSS scanning, then @import the plugin's CSS files into your Tailwind CSS file.
main.css@import "tailwindcss"; /* @preline/remove-element */ /* [!code highlight:3] */ @source "../node_modules/@preline/remove-element/*.js"; @import "./node_modules/@preline/remove-element/variants.css"; @import "./node_modules/@preline/remove-element/theme.css"; -
Add the plugin JavaScript
Include the JavaScript
<script>that powers the interactive elements near the end of your</body>tag:HTML
Additional Initialization Options
Use the
non-autoentry if you need manual initialization. In this mode, automatic initialization on page load is not included, so the component should be initialized explicitly.HTML (non-auto)
Via bundler
When using a bundler (Vite, webpack, etc.), import the plugin directly as an ES module.
JavaScript (auto)import "@preline/remove-element";JavaScript (non-auto)import HSRemoveElement from "@preline/remove-element/non-auto"; HSRemoveElement.autoInit(); // Or initialize a specific element manually const el = document.querySelector("#remove-element"); if (el) new HSRemoveElement(el);
Basic usage
Prefer to create your own style? Here is a completely unstylized example.
<div id="dismiss-unstyled" class="inline-flex justify-between items-center w-full">
<h3>
Remove element card
</h3>
<button type="button" class="inline-flex justify-center items-center size-4" data-hs-remove-element="#dismiss-unstyled">
<span class="sr-only">Close</span>
<svg class="shrink-0 size-4" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M18 6 6 18"/><path d="m6 6 12 12"/></svg>
</button>
</div>
Methods
The HSRemoveElement object is contained within the global window object
Destroy instance.
const { element } = HSRemoveElement.getInstance('#remove-element', true);
const destroyBtn = document.querySelector('#destroy-btn');
destroyBtn.addEventListener('click', () => {
element.destroy();
});
Ready to use Components
Looking for prebuilt UI components based on the Tailwind CSS? Preline UI packs hundreds of component examples for all your website needs.
Remove Element
Explore ready-to-use Tailwind CSS examples built with Preline UI.
View Remove Element examples