How to use HTML replaceAll Method in JQuery

This article describe about HTML ReplaceAll Method in JQuery.
  • 2117

HTML replaceAll() method in jQuery

The replaceAll() method replaces all selected elements with the matched elements.

Syntax

$(content).replaceAll(selector)

  • selector : selector allow elements to find and replace the matched elements with.

Example

Following is a simple example a showing the usage of this method.

<!DOCTYPE html>

<html>

<head>

<script type="text/javascript" src="jquery.js"></script>

<script type="text/javascript">

    $(document).ready(function ()

{

        $("button").click(function ()

{

            $("<b>Hello world!</b>").replaceAll("p");

        });

    });

</script>

</head>

<body>

<p>This is a JQuery.</p>

<p>This is .Netheaven.</p>

<button>Replace each p element after click this button</button>

</body>

</html>

Output1

op1.jpg

Output2

op2.jpg

You may also want to read these related articles here

Ask Your Question 

Got a programming related question? You may want to post your question here

Programming Answers here

© 2020 DotNetHeaven. All rights reserved.