Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

jQuery replaceWith() method

jQuery replaceWith() method

jQuery HTML/CSS methods jQuery HTML/CSS methods

Example

Replace the first

element with new text:

$

(

"

button

"

)

.

click

(

function

(

)

{

$

(

"

p:first

"

)

.

replaceWith

(

"

Hello world!

"

)

;

}

)

;

Try it »


Definition and Usage

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


Syntax

$(

selector

).replaceWith(

content,

function(

index

))

Parameters Description
content Required. Specifies the content to insert (may contain HTML tags).

Possible values:

  • HTML element
  • jQuery object
  • DOM element
  • | | function(*index*) | Optional. Specifies a function that returns the replacement content. |

    More examples

    Replacing content using a function
    How to use a function to replace the selected elements with new content.


    jQuery HTML/CSS methods jQuery HTML/CSS methods