jQuery replaceWith()メソッド
例
最初の<p>要素を新しいテキストに置き換えます。
$("button").click(function(){
$("p:first").replaceWith("Hello world!");
});
定義と使用法
replaceWith()メソッドは、選択した要素を新しいコンテンツに置き換えます。
構文
$(selector).replaceWith(content,function(index))
Parameter | Description |
---|---|
content | Required. Specifies the content to insert (can contain HTML tags)
Possible values:
|
function(index) | Optional. Specifies a function that returns the content to replace
|
自分で試してみてください-例
置き換える関数を使用して、選択した要素を新しいコンテンツに置き換える方法。