25 of 119 menu

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:

$(how than whereby wherewith_replace).replaceWith(what)_replace);

Example

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

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

HTML the code will look like this:

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

See also

  • method replaceWith,
    which also replaces some elements with others
azbydeenesfrkakkptruuz