components

Tailwind CSS Remove element

Easily remove elements with just a single click, streamlining your workflow and enhancing user experience.

Class Name
Type
Description
removing:ModifierWhen the removal process starts, it applies a specified class.

Include the data-remove-element attribute in the close button element and set its value to #id to specify the element to be removed. Customize the removal animation by incorporating the removing: modifier, as illustrated below.

Below example demonstrates use of remove-element in badges.

Below example demonstrates use of remove-element in alerts.

The destroy method is provided to facilitate the destruction of a remove element.

In the data-remove-element-options attribute, assign an object as its value.

Within this object, define the removeTargetAnimationClass key as a Tailwind CSS class, which will be applied during the removal process.By default, this value is derived from the modifier class removing:, but it can also be specified using this data attribute option.

PARAMETERS
DESCRIPTION
OPTIONS
DEFAULT VALUE
data-remove-elementThe element to be removed. This must be a valid selector.-null
data-remove-element-optionsOption that can be added via the data attribute.--
:removeTargetAnimationClassSome valid TailwindCSS class.stringremoving

The HSRemoveElement object is contained within the global window object.

METHOD
DESCRIPTION
PUBLIC METHODS
destroy()Destroys the instance, removes generated markup (if any), removes added classes and attributes.
STATIC METHODS
HSRemoveElement.getInstance(target, isInstance)
Returns the element associated to the target.
  • target should be a Node or string (valid selector).
  • isInstance boolean. Returns the instance instead of Node if true.

Destroy the instance if the `Id` is added to the `data-remove-element` attribute, or use it as shown in the example above.

const { element } = HSRemoveElement.getInstance('#remove-element', true);
const destroyBtn = document.querySelector('#destroy-btn');

destroyBtn.addEventListener('click', () => {
  element.destroy();
});