jQuery Document Operation - append() Method

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 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))

Try It Yourself

Parameters Description
function(index,html)

Required. Specifies the function that returns the content to be inserted.

  • index - Optional. Receives the index position of the selector.
  • html - Optional. Receives the current HTML of the selected selector.