Easy Tutorial
❮ Eff Slidedown Jquery Ajax Intro ❯

jQuery replaceWith() Method

jQuery HTML/CSS Methods

Example

Replace the first <p> element with new text:

$("button").click(function(){
    $("p:first").replaceWith("Hello world!");
});

Definition and Usage

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


Syntax

Parameter Description
content Required. Specifies the content to insert (can include HTML tags). Possible values: HTML element<br> jQuery object<br> DOM element
function(index) Optional. Specifies a function that returns the replacement content. index - Returns the index position of the element in the set.

More Examples

Replace Content with a Function


jQuery HTML/CSS Methods

❮ Eff Slidedown Jquery Ajax Intro ❯