jQuery Tutorial Tutorials - jQuery .replaceAll() method

jQuery .replaceAll() method

The .replaceAll(target) method in jQuery is used to replace the target element with the matched elements from the DOM.

jQuery .replaceAll() method Syntax

.replaceAll(target)

target is a jQuery object, DOM element(s), or selector string indicating which element(s) to replace.

jQuery .replaceAll() method Example

example

Create an element and replace paragraphs with it.
HTML

<div class="container">
    <p>Learn JavaScript</p>
    <p>Learn jQuery</p>
    Lautturi tutorial
</div>

jQuery

$('<b>Learning online</b>').replaceAll('p');

Result

<div class="container">
    <b>Learning online</b>
    <b>Learning online</b>
    Lautturi tutorial
</div>

Try now

example

Select an element and replace paragraphs with it.
Please note that the selected element is moved from its old location but not cloned.

HTML

<div class="container">
    <p class="js">Learn JavaScript</p>
    <p class="cpp">Learn C++</p>
    <p class="jquery">Learn jQuery</p>
</div>

jQuery

$('.jquery').replaceAll('.js');

Result

<div class="container">
    <p class="jquery">Learn jQuery</p>
    <p class="cpp">Learn C++</p>
</div>
Date:2019-08-25 10:30:10 From:www.Lautturi.com author:Lautturi