English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
The insertAfter() method inserts the specified HTML element after the selected element.
To insert an HTML element before the selected element, useinsertBefore()method.
Inafter()Performs the same task as the insertAfter() method. The main difference is in the syntax:
Useafter()The expression is chosen before the function, and the parameter is the content to be inserted.
UseinsertAfter()is exactly the opposite, the content is in front of the method, and it will be placed after the element specified by the parameter.
$(content).insertAfter(selector)
Insert an HTML element after each paragraph:
$("button").click(function(){ $("<p style="39;color:red;'>Hello world</p>").insertAfter("p"); });Test and see‹/›
Use the insertAfter() method to insert an existing element after each selected element:
$("button").click(function(){ $("h1").insertAfter("p"); });Test and see‹/›
Parameter | Description |
---|---|
content | Specify the content to be inserted (must contain HTML tags) Possible values:
|
selector | The selected element will be inserted after the element specified by this parameter |