The jQuery add() method is used to add element to the existing group of elements. This method can add element to the whole document, or just inside context element if the context parameter is defined.
Syntax:
$(selector).add(element, context_parameter)
Here selector helps to find the matching element.
Parameters: It accept two parameters that are specified below:
jQuery code to show the working of add() method:
<html> <head> /jquery/3.3.1/jquery.min.js"></script> <script> $(document).ready(function() { $(".heading").add("#para1").add("#span1"). css("background-color", "lightgreen"); }); </script> </head> <body> <p style="color:green" class="heading">Welcome to GfG!!!</p> <p style="color:green" id="para1">Welcome to GeeksforGeeks !!!</p> <span style="color:green" id="span1">Article 1 !!!.</span> <div>This example adds the same css style for both "p" and "span" elements, using its class and id name!!! </div> </body> </html> |
chevron_right
filter_none
Output:

Recommended Posts:
- jQuery | jQuery.fx.interval Property with example
- How to add class to an element without addClass() method in jQuery ?
- jQuery callbacks.add() Method
- jQuery | Add Elements with Examples
- How to add table row in a table using jQuery?
- How to Add and Remove multiple classes in jQuery ?
- How to add options to a select element using jQuery?
- How to add `style=display:“block”` to an element using jQuery?
- How to add target="_blank" to a link using jQuery ?
- How to Dynamically Add/Remove Table Rows using jQuery ?
- How to add content in <head> section using jQuery/JavaScript?
- How to add <li> class to active and leave it after hover using jQuery ?
- jQuery | jQuery.fx.off Property
- jQuery | jQuery.support Property
- jQuery | jquery Property
- jQuery | event.timeStamp property with Example
- jQuery | focusout() with Example
- jQuery | parentsUntil() with Example
- jQuery | event.relatedTarget Property with Example
- jQuery | event.target Property with Example
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


