jQuery appendTo()メソッド

❮jQueryHTML/ CSSメソッド

各<p>要素の最後に<span>要素を挿入します。

$("button").click(function(){
  $("<span>Hello World!</span>").appendTo("p");
});

定義と使用法

appendTo()メソッドは、選択した要素の最後にHTML要素を挿入します。

ヒント:選択した要素の先頭にHTML要素を挿入するには、 prependTo()メソッドを使用します。


構文

$(content).appendTo(selector)

Parameter Description
content Required. Specifies the content to insert (must contain HTML tags).

Note: If content is an existing element, it will be moved from its current position, and inserted at the end of the selected elements.
selector Required. Specifies on which elements to append the content to

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


appendTo()メソッドを使用して、選択した各要素の最後に既存の要素を挿入する方法。


❮jQueryHTML/ CSSメソッド