JQuery Add

 

The add() method is used to add element to the existing group of elements.

This example adds the same css style for both p and span elements with the existing h1 element.

 
 
 
<!DOCTYPE html> <html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.0/jquery.min.js"></script> <script> $(document).ready(function(){ $("h1").add("p").add("span").css("background-color", "cyan"); }); </script> </head> <body> <h1>Welcome to india</h1> <p>please Add paragraph.</p> <p>Another p element.</p> <span>A span element.</span> <span>A span element.</span><br><br> </body> </html>
Output