Javascript examples for jQuery Method and Property:add
The add() method adds elements to an existing group of elements.
Parameter | Require | Description |
---|---|---|
element | Required. | a selector expression, a jQuery object, one or more elements or an HTML snippet to be added |
context? | Optional. | point in the document where the selector expression should begin matching |
The following code shows how to Add <p> and <span> elements to an existing group of elements (<h1>):
<!DOCTYPE html> <html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> <script> $(document).ready(function(){ $("h1").add("p").add("span").css("background-color", "yellow"); });// w ww . jav a 2 s .c om </script> </head> <body> <h1>Welcome</h1> <p>A p element.</p> <p>Another p element.</p> <span>A span element.</span> <span>A span element.</span><br><br> </body> </html>