jQuery insertAfter()メソッド
例
各<p>要素の後に<span>要素を挿入します。
$("button").click(function(){
$("<span>Hello world!</span>").insertAfter("p");
});
定義と使用法
insertAfter()メソッドは、選択した要素の後にHTML要素を挿入します。
ヒント:選択した要素の前にHTML要素を挿入するには、 insertBefore()メソッドを使用します。
構文
$(content).insertAfter(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 after the selected elements. |
selector | Required. Specifies where to insert the content |
自分で試してみてください-例
insertAfter()メソッドを使用して、選択した各要素の後に既存の要素を挿入する方法。