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.

Syntax

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

Example

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.

HTML

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.

jQuery

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

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