Example
Insert content at the end of each p element:
$("button").click(function(){
$("p").append(" <b>Hello world!</b>");
}); |
Try it yourself »
|
Definition and Usage
The append() method inserts specified content at the end of (but still inside) the selected elements.
Tip: The append() and appendTo()
methods do the same thing. The difference is in the syntax: the placement of the content and selector,
and that appendTo() cannot append content using a function.
Syntax
$(selector).append(content) |
Parameter |
Description |
content |
Required. Specifies the content to insert (can contain HTML
tags) |
Append Content Using a Function
Using a function to insert specified content at the end of the selected elements.
Syntax
Parameter |
Description |
function(index,html) |
Required. Specifies a function that returns the content to insert.
- index - Optional. Receives the index position of the selector
- html - Optional. Receives the current HTML of the selector
|