Skip to the content.

$.fn.add(selector)

Create a new Dabby collection by appending elements to the end of the current collection. Duplicate nodes are removed so each element appears at most once.

Signatures

add(selector: Selector): this;

Parameters

Returns

A new Dabby collection containing the original nodes followed by the added nodes, with duplicates removed.

Examples

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

// Combine selections by selector
$("button").add("a.button").addClass("clickable");
import $ from "dabbyjs";
import "dabbyjs/traversal/add/add";

// Add a freshly-created element to an existing collection
const $existing = $(".product");
const $new = $("<div class='product'>New product</div>");
const $all = $existing.add($new);
import $ from "dabbyjs";
import "dabbyjs/traversal/add/add";

// Build a collection across several form field types
const $fields = $("form").find("input")
    .add($("form").find("textarea"))
    .add($("form").find("select"));

See also