jQuery Traversal - add() Method
Example
Find all div elements and add a border to them. 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 used to find elements to be added to the matching element collection. |
Syntax 2
.add(elements)
Parameters |
Description |
elements |
Add one or more elements to the matching element collection. |
Syntax 3
.add(html)
Parameters |
Description |
html |
Add an HTML fragment to the matching element collection. |
Syntax 4
.add(jQueryObject)
Parameters |
Description |
jQueryObject |
Add an existing jQuery object to the matching element collection. |
Syntax 5
.add(selector, context)
Parameters |
Description |
selector |
A string value representing the selector expression used to find elements to be added to the matching element collection. |
context |
The position where the selector starts matching. |
Detailed description
None.