jQuery .add() Method
Last Updated Jul 21, 2015, 12:00:06 PM
jQuery .add() Method
jQuery add()
method adds HTML
elements to an existing group of elements.
Syntax
Let us look at an example of how we can use the jquery traversal .add() method
ExampleBelow 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.
HTMLSee 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 ReferencejQuery 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
Learning 200 jQuery Functions with 800 Examples -Udemy
Learn jQuery in One Month - from OneMonth
The Ultimate Web Development Course -Udemy
Learn jQuery: An In-depth Course For Beginners -Udemy