Home >>jQuery Tutorial >jQuery replaceAll() Method

jQuery replaceAll() Method

jQuery replaceAll() Method

jQuery replaceAll() method in jQuery is an inbuilt method and is used to add new HTML elements that replaces the selected elements.

Syntax:
$(content).replaceAll(selector)

Parameter Values

Parameter Description
content It is required parameter to specify the content to insert
selector It is a required parameter and is used to Specifies which elements to be replaced
Here is an Example of jQuery replaceAll() Method:

<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$(".btn1").click(function(){
$("<h3>Hello Phptpoint!!</h3>").replaceAll(".txt1");
});
});
</script>
</head>
<body>
<button class="btn1">Replace all p elements with h3 elements</button><br>
<p class="txt1">This is First paragraph.</p>
<p class="txt1">This is Second paragraph.</p>
<p class="txt1">This is Third paragraph.</p>
</body>
</html>

Output:

This is First paragraph.

This is Second paragraph.

This is Third paragraph.