English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
The append() method inserts the specified content at the end of each selected element (as the last child element).
To insert content at the beginning of the selected element, useprepend()Method.
Insert content:
$(selector).append(content)
Insert content using a function:
$(selector).append(function(index, html))
Add some text content to all paragraphs:
$("button").click(function(){ $("p").append("Hello world"); });Test and see‹/›
Insert HTML into all paragraphs:
$("button").click(function(){ $("p").append("<b>Hello world</b>");/b>"); });Test and see‹/›
This example uses document.createTextNode() to create a text node and insert it into all <p> elements:
$("button").click(function(){ $("p").append(document.createTextNode("Hello world")); });Test and see‹/›
Insert content using a function:
$("button").click(function(){ $("p").append(function(i){ return "<b>The p element has index " + i + ".</b>"; }); });Test and see‹/›
Parameter | Description |
---|---|
content | Specify the content to be inserted at the end of each selected element (can include HTML tags) Possible values:
|
function(index, html) | Specify a function that returns the content to be inserted
|