Skip to the content.

$.fn.filter(selector) / $.fn.is(selector) / $.fn.not(selector)

Three closely-related methods that test or narrow a collection against a selector or callback.

Signatures

filter(selector: Selector | ((this: Element, index: number) => boolean)): this;
is(selector: Selector | ((this: Element, index: number) => boolean)): boolean;
not(selector: Selector): this;

Parameters

Returns

Examples

import $ from "dabbyjs";
import "dabbyjs/traversal/filter/filter";

// Keep only the visible items
$(".item").filter(":not(.hidden)");
import $ from "dabbyjs";
import "dabbyjs/traversal/filter/filter";

// Drop items already marked as complete
$(".task").not(".complete").addClass("pending");
import $ from "dabbyjs";
import "dabbyjs/traversal/filter/filter";

// Use a callback for arbitrary tests
$("input").filter(function () {
    return (this as HTMLInputElement).value.length > 0;
});
import $ from "dabbyjs";
import "dabbyjs/traversal/filter/filter";

// Boolean check
if ($("#submit").is(":disabled")) {
    showLoadingMessage();
}

See also