jQuery Document Operation - appendTo() Method

Example

Insert content at the end of each p element:

$("button").click(function() {
  $("<b>Hello World!</b>").appendTo("p");
});

Try It Yourself

Definition and Usage

The appendTo() method inserts the specified content at the end of the selected element (still inside).

Tip:append() The same task as the appendTo() method. The difference is: the position of content and selector, and append() can use functions to append content.

Syntax

content).appendTo(selector)
Parameters Description
content Required. Specifies the content to be inserted (can include HTML tags).
selector Required. Specifies the element to which the content should be appended.