⊗jqDmERRw 60 of 113 menu

Replacing Elements with jQuery's replaceWith Method

You can replace one element with another using the replaceWith method.

Let's look at an example, let's say we have the following paragraphs:

<p class="www">text</p> <p class="www">text</p> <p class="www">text</p> <p>text</p>

Let's replace all paragraphs with class www with '<div>!!!</div>':

$('.www').replaceWith('<div>!!!</div>');

HTML the code will look like this:

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

Replace each h2 with its contents.

Replace each h2 with its contents, after wrapping the contents in a paragraph.

enru