Edit this page

up.fragment up.destroy(target, [options])
JavaScript function

Destroys the given element or selector.

All registered destructors are called. The element is then removed from the DOM.

Unfinished requests targeting the destroyed fragment or its descendants are aborted.

Emits events up:fragment:destroyed.

Animating the removal

You may animate the element's removal by passing an option like { animate: 'fade-out' }. Unpoly ships with a number of predefined animations and you may so define custom animations.

If the element's removal is animated, the element will remain in the DOM until after the animation has completed. While the animation is running the element will be given the .up-destroying class. The element will also be given the [aria-hidden] attribute to remove it from the accessibility tree.

Elements that are about to be destroyed (but still animating) are ignored by all functions that lookup fragments, like up.fragment.all(), up.fragment.get() or up.fragment.closest().

Detecting destructor errors

If a destructor throws an error, up.destroy() will still remove the element and not throw an error.

Instead compiler errors will print to the error console and emit an error event on window.

See errors in user code for details.


Parameters

target stringorElementorjQuery
[options.animation='none'] stringorFunction(element, options): Promise optional

The animation to use before the element is removed from the DOM.

[options.duration] number optional

The duration of the animation. See up.animate().

[options.easing] string optional

The timing function that controls the animation's acceleration. See up.animate().

[options.onFinished] Function optional

A callback that is run when any animations are finished and the element was removed from the DOM.

Return value

undefined