jQuery Document Operation - append() Method
Example
Insert content at the end of each p element:
$("button").click(function(){ $("p").append(" <b>Hello world!</b>"); });
Definition and Usage
The append() method inserts the specified content at the end (still inside) of the selected element.
Tip:append() and appendTo() The task performed by the method is the same. The difference is: the position of the content and the selector.
Syntax
$("selector").append(content)
Parameters | Description |
---|---|
content | Required. Specifies the content to be inserted (can include HTML tags). |
Use a function to append content
Use a function to insert content at the end of the specified element.
Syntax
$("selector").append(function(index,html))
Parameters | Description |
---|---|
function(index,html) |
Required. Specifies the function that returns the content to be inserted.
|