$.fn.filter(selector) / $.fn.is(selector) / $.fn.not(selector)
Three closely-related methods that test or narrow a collection against a selector or callback.
filter— keep elements that match.not— keep elements that do not match.is— return a boolean: does at least one element match?
Signatures
filter(selector: Selector | ((this: Element, index: number) => boolean)): this;
is(selector: Selector | ((this: Element, index: number) => boolean)): boolean;
not(selector: Selector): this;
Parameters
selector(Selector | (this: Element, index: number) => boolean) — a CSS selector, node, Dabby collection, or callback. The callback receives the element’s index and is bound (this) to the element; returntrueto keep the element.
Returns
filterandnotreturn a new Dabby collection.isreturns aboolean.
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();
}