jQuery replaceWith() method
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: |
- index - Returns the index position of the element in the set.
More examples
Replacing content using a function
How to use a function to replace the selected elements with new content.
jQuery HTML/CSS methods