jQuery .add() Method

Last Updated Jul 21, 2015, 12:00:06 PM

jQuery .add() Method

jQuery add() method adds HTMLelements to an existing group of elements.


Let us look at an example of how we can use the jquery traversal .add() method


Below example program will find all div elements, creates a border and then adds all paragraphs to the jQuery object to set their backgrounds as green.


See the above HTML code. We have 6 div elements and one paragraph. Using the below jQuery add() method we can simply target the div elements and style those div elements with red color border ( "border", "2px solid red" ) and also set the background to green.


When you run the above jQuery add() method example, it will produce the following output

Try It Now

Other Advanced jQuery Traversing Methods you might want to learn

jQuery Traversal Reference

jQuery Basic Traversing

jQuery Traversal Filters

jQuery Traversing Methods

Sources and Credits

The content and methods in the tutorial has been referred and updated with jQuery API and The jQuery Foundation

Last Updated Jul 21, 2015, 12:00:06 PM