Skip to the content.

$.fn.remove([selector]) / $.fn.detach([selector])

Remove elements from the DOM. The two methods differ only in what they do with the data and events bound to the removed nodes:

Both accept an optional selector to filter which elements in the collection get removed.

Signatures

remove(selector?: Selector): this;
detach(selector?: Selector): this;

Parameters

Returns

The original Dabby collection for chaining (with the removed elements still referenced by it, so you can re-insert them later).

Examples

import $ from "dabbyjs";
import "dabbyjs/manipulation/remove/remove";

// Remove every error message
$(".error").remove();
import $ from "dabbyjs";
import "dabbyjs/manipulation/remove/remove";

// Filter inside the collection — drop only items marked complete
$("li.task").remove(".complete");
import $ from "dabbyjs";
import "dabbyjs/manipulation/remove/remove";

// detach — re-insert later with handlers intact
const $widget = $("#widget").detach();
$("#sidebar").append($widget);

See also