English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
The replaceWith() method replaces the selected element with new content.
The replaceWith() method is similar toreplaceAll()butcontentandselectorOn the contrary.
Replacement content:
$(selector).replaceWith(content)
Use feature to replace content:
$(selector).replaceWith(function(index))
Replace all paragraphs with <h1>Element:
$("button").click(function(){ $("p").replaceWith("<h1>New Title</h1>"); });Test See‹/›
Use feature to replace content:
$("button").click(function(){ $("p").replaceWith(function(i){ return "<h2>This element has index " + i + ".</h2>"; }); });Test See‹/›
Parameter | Description |
---|---|
content | Specify the content to be inserted (can include HTML tags) Possible values:
|
function(index) | Specify a function that returns the HTML content to be replaced
|