English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

jQuery appendTo() Method

jQuery HTML/CSS Methods

The appendTo() method inserts HTML elements at the end of the selected element (as the last child element).

To insert an HTML element at the beginning of the selected element, useprependTo()Method.

append()The difference between the append() method and the appendTo() method:

  • Useappend()to append content to the interior of each matching element.

  • UseappendTo()Append all matching elements to the specified element collection.

  $('div').append('<span>Hello</span>'); 
  // is equivalent to
  $('<span>Hello</span>').appendTo('div');
  // Result => <div>World<span>Hello</span></div>

Syntax:

$(content).appendTo(selector)

Example

Add a <b> element at the end of all paragraphs:

$("button").click(function(){
  $("<b>Hello world</b>").appendTo("p");
});
Test and see‹/›

Use the appendTo() method to insert an existing element at the end of each selected element:

$("button").click(function(){
  $("h1").appendTo("p");
});
Test and see‹/›

Parameter Value

ParameterDescription
contentSpecify the content to be inserted (must contain HTML tags)

Possible Values:

  • HTML Element

  • DOM Element

  • jQuery Object

selectorThe selected element will be inserted at the end of the element specified by this parameter

jQuery HTML/CSS Methods