Home >>jQuery Tutorial >jQuery add() Method

jQuery add() Method

jQuery add() Method

jQuery add() method in jQuery is used to adds elements to an existing group of elements.

Syntax:

$(selector).add(element,context)

Parameter Values

Parameter Description
element It is a Required parameter and used to specifies a selector expression, a jQuery object, one or multiple elements or an HTML snippet to be added to an existing group of elements
context It is an Optional parameter and used to specifies the point in the document at which the selector expression should begin matching

Here is an Example of jQuery add() Method:


<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$(".heading").add(".para").add(".txt").css("background-color", "#df65f7");
});
</script>
</head>
<body>
<h1 class="heading">Welcome</h1>
<p class="para">Phptpoint</p>
<p class="para">Hello World</p>
<span class="txt">Hello..</span>
<span class="txt">How are you !</span><br><br>
</body>
</html>

Output:

Welcome

Phptpoint

Hello World

Hello.. How are you !
 

No Sidebar ads