jQuery after()メソッド

❮jQueryHTML/ CSSメソッド

各<p>要素の後にコンテンツを挿入します。

$("button").click(function(){
  $("p").after("<p>Hello world!</p>");
});

定義と使用法

after()メソッドは、選択された要素の後に指定されたコンテンツを挿入します。

ヒント:選択した要素の前にコンテンツを挿入するには、 before()メソッドを使用します。


構文

$(selector).after(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) Specifies a function that returns the content to insert
  • index - Returns the index position of the element in the set

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


after()メソッドを使用してコンテンツを挿入します。


挿入する関数を使用して、選択した要素の後にコンテンツを挿入する方法。


❮jQueryHTML/ CSSメソッド