jQuery Traversal - add() Method

Example

Find all div elements and add a border. Then add all paragraphs to the jQuery object and set their background to yellow:

$("div").css("border", "2px solid red")
        .add("p")
        .css("background", "yellow");

Definition and Usage

The add() method adds elements to the collection of matched elements.

Syntax 1

.add(selector)
Parameters Description
selector A string value representing the selector expression to find elements to be added to the matched element collection.

Syntax 2

.add(elements)
Parameters Description
elements Add one or more elements to the matched element collection.

Syntax 3

.add(html)
Parameters Description
html Add HTML fragments to the matched element collection.

Syntax 4

.add(jQueryObject)
Parameters Description
jQueryObject Add existing jQuery objects to the matched element collection.

Syntax 5

.add(selector, context)
Parameters Description
selector A string value representing the selector expression to find elements to be added to the matched element collection.
context The position where the selector starts matching.

Detailed Description

None.