Open In App

jQuery replaceAll() Method

The replaceAll() method is an inbuilt method in jQuery that is used to replace selected elements with new HTML elements.

Syntax:



$(content).replaceAll(selector)

Parameters:

This method accepts two parameters as mentioned above and described below:



Return Value: This method returns the selected elements with new content.

The below program illustrates the above function:

Example:




<!DOCTYPE html>
<html>
 
<head>
    <title>The replaceAll Method</title>
    <script src=
    </script>
 
    <!-- jQuery code to show the working of this method -->
    <script>
        $(document).ready(function () {
            $("button").click(function () {
                $("<h1>GeeksforGeeks!</h1>").replaceAll("p");
                $("h1").css({ "color": "green" });
            });
        });
    </script>
    <style>
        div {
            width: 60%;
            height: 150px;
            padding: 10px;
            border: 2px solid green;
            font-size: 20px;
            text-align: center;
        }
 
        p {
            font-size: 25px;
            font-weight: bold;
        }
    </style>
</head>
 
<body>
    <div>
        <p>Welcome to </p>
 
        <!-- click on this button and see the change -->
        <button>Click Here!</button>
        <br>
    </div>
</body>
 
</html>

Output:


Article Tags :