jQuery replaceWith()メソッド

❮jQueryHTML/ CSSメソッド

最初の<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:

  • HTML elements
  • jQuery objects
  • DOM elements
function(index) Optional. Specifies a function that returns the content to replace
  • index - Returns the index position of the element in the set

自分で試してみてください-例


置き換える関数を使用して、選択した要素を新しいコンテンツに置き換える方法。


❮jQueryHTML/ CSSメソッド