The replaceAll method

The replaceAll method replaces some elements with others. It works similarly to the replaceWith method.

Syntax

The method parameter can be text (possibly with tags), an array, a DOM element, or a jQuery object:

javascript$(elements).replaceWith(elements);

Example

Let's replace all paragraphs with class www with a div with text '!!!':

html<p class="www">text</p>
<p class="www">text</p>
<p class="www">text</p>
<p>text</p>
javascript$('<div>!!!</div>').replaceAll('p.www');

HTML the code will look like this:

html<div>!!!</div>
<div>!!!</div>
<div>!!!</div>
<p>text</p>

See also

  • method replaceWith,
    which also replaces some elements with others