JQuery add()
The add()
method in jQuery is used to add one or more elements to the selected set of elements. It can be used to add new content to the DOM or to modify existing content.
Syntax
The basic syntax for the add()
method is as follows:
$(selector).add(content, context);
selector
: The jQuery selector that selects the initial set of elements.content
: The content to add to the selected set of elements.context
: The context in which to search for thecontent
parameter.
Use
The add()
method is useful when you want to add new content to an existing DOM selection. It can also be used to create a new selection that combines multiple selections.
Example
Here is an example of using the add()
method to add a new div
element to an existing selection: