jQuery replaceAll() Method

The jQuery replaceAll() method can be used to replace all the selected elements with the specified HTML tags. It replaces all elements as well as its content with the other HTML element.

jQuery replaceAll() Method

Syntax

The syntax of this method is given below:-

Syntax
$(content).replaceAll(selector)

Description of the Parameters

The description of these parameters is given below.

Parameter Name Description
selector Specify the element to select and replace all the elements. You can use the element tag name, class name, or id to select. It is a required field.
content You have to specify the HTML element to replace it with the selected element. It is an HTML tag or element that can contain some text content. It is a required field.

jQuery replaceAll() Method to Replace All Selected Element

If you want to replace the element from the specified element, you have to use the method as given below. There are three paragraph elements, you have to replace all of them with em element.

Example

Test it Live

Output

First paragraph.

Second paragraph.

Third paragraph.


When you click the button given above, it replaces the paragraph element with the em elements. After the replacement, the output contains the three em element.

You may also like to read

I hope you like this tutorial on jQuery replaceAll() method. If you have any queries regarding the tutorial, please comment below.

References