Example of .add() in jQuery
February 16, 2013
.add() in jQuery can add DOM elements logically together with which we can apply any css or any addclass for all those DOM elements that have been added by .add() method. As an arguments .add() can accept the below parameters.
.add( selector ) .add( elements ) .add( html )
<!DOCTYPE html> <html> <head> <script src="http://code.jquery.com/jquery-latest.js"></script> </head> <body> <p>My</p> <span>name is</span> <b>Atul</b> <script>$("p").add("span").add("b").css("background", "red");</script> </body> </html>
Run the program and output will look like
My
name is Atul