English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

jQuery after() Method

jQuery HTML/CSS Methods

the after() method to insert specified content after the selected element.

To insert content before the selected element, please usebefore()Method.

Syntax:

Inserting content:

$(selector).after(content)

Inserting content using a function:

$(selector).after(function(index))

Instance

Inserting content after each paragraph:

$("button").click(function(){
  $("p").after("<p>Hello world</p>");
});
Test See‹/›

Inserting content using a function:

$("button").click(function(){
  $("p").after(function(i){
    return "<p>This p element's index: " + i + ".</p>";
  });
});
Test See‹/›

Parameter Value

ParameterDescription
contentSpecify the content to be inserted after each selected element (can include HTML tags)

Possible values:

  • HTML Element

  • DOM Element

  • jQuery Object

function(index)Specify a function that returns the content to be inserted
  • index-Return the index position of the element in the collection

jQuery HTML/CSS Methods