jQuery Tutorial

jQuery Methods for Replacing Elements

jQuery replaceAll() Method

The replaceAll() method in jQuery swaps out selected HTML elements for new ones.

Syntax of replaceAll method in jQuery


Example of jQuery replaceAll method


elements should be replaced with


Hello world!

jQuery replaceWith() Method

This method replaces selected elements with new content using the replaceWith() method.

Syntax of replaceWith method in jQuery


Example of jQuery replaceWith method

Replace the text in the first

element with the following:

$("p:first").replaceWith("Hello world!");
Did you find this article helpful?