Home >Web Front-end >JS Tutorial >Analyze the two uses of after in jQuery
Definition and usage
after() method inserts the specified content after the selected element.
Syntax
$(selector).after(content)
Parameter Description
content Required. Specifies the content to be inserted (can include HTML tags).
Use the function to insert content
Use the function to insert the specified content after the selected element.
Syntax
$(selector).after(function(index))
Parameter Description
function(index)
Required. Specifies a function that returns the content to be inserted.
index - Optional. Receives the index position of the selector.
Method 1:
Insert content after each p element:
The code is as follows:
$("button").click(function(){ $("p").after("<p>Hello world!</p>"); });
Method 2:
The code is as follows:
$("button").click(function(){ $("p").after(function(n){ return "<p>The p element above has index " + n + "</p>"; }); });
after in function must return an html string .
The above is the detailed content of Analyze the two uses of after in jQuery. For more information, please follow other related articles on the PHP Chinese website!