Code has been added to clipboard!

What's jQuery .appendTo() and How It Differs From .append()?

Reading time 1 min
Published Jan 18, 2018
Updated Sep 27, 2019

jQuery appendTo: Main Tips

  • jQuery .appendTo() inserts HTML elements at the end of the selected element. To insert it at the beginning, use .prependTo().
  • This method works in the same way as .append(), but the syntax is different. This might seem insignificant but comes in handy when you use chaining.

Writing and Using .appendTo()

The jQuery .appendTo() method inserts specified elements at the end of the selected element (one or multiple). The elements you define will appear inside the selected element's tag but after all other content.

In the example below, you can see jQuery append to a <h1> element:

Example
$("button").click(() => {
    $("<span>Breaking news!</span>").appendTo("h1");
});

The syntax for jQuery .appendTo() is as follows:

$(content).appendTo(target);

The content defines the content to be added to the target elements.

Note: in this case, target (or selector in other words) precedes the function, differently from .append() .

Learn jQuery
Introduction
Selectors
Events
Event Methods
Download
Callback
Chaining
Get and Set
Add Element
Remove Element
Traverse
Parent
Children
Sibling Traverse
Filtering
jQuery AJAX
Effects
Show and Hide
Fade Effect
Slide Effect
Animate Effect
Manipulate CSS
Width and Height
.addClass()
.after()
.animate()
.append()
.appendTo()
.attr()
.before()
.bind() (deprecated)
.blur()
.change()
.click()
.clone()
.css()
.dblclick()
.delay()
.delegate() and .undelegate() (deprecated)
.detach()
.empty()
.end()
.error() (deprecated)
.fadeIn()
.fadeOut()
.fadeTo()
.fadeToggle()
.finish()
.focus()
.focusIn()
.focusOut()
.hasClass()
.height()
.hide()
.hover()
.html()
.innerHeight()
.innerWidth()
.insertAfter()
.insertBefore()
.keypress()
.keyup()
.live() and .die() (deprecated)
.load() (deprecated)
.mousedown()
.mouseenter()
.mouseleave()
.mousemove()
.mouseout()
.mouseover()
.mouseup()
.off()
.offset()
.offsetParent()
.on()
.one()
.outerHeight()
.outerWidth()
.position()
.prepend()
.prependTo()
.prop()
.proxy()
.queue()
.ready()
.remove()
.removeAttr()
.removeClass()
.removeProp()
.replaceAll()
.replaceWith()
.resize()
.scroll()
.scrollLeft()
.scrollTop()
.show()
.slideDown()
.slideToggle()
.slideUp()
.stop()
.submit()
.text()
.toggle()
.toggleClass()
.trigger()
.triggerHandler()
.unbind() (deprecated)
.unload() (deprecated)
.unwrap()
.val()
.width()
.wrap()
Event Properties
event.currentTarget
event.preventDefault()
event.relatedTarget
event.stopImmediatePropagation()
event.stopPropagation()
event.target
event.timeStamp
event.type
event.which
jQuery .find()
jQuery .keydown()
jQuery.noConflict()
pageY and pageX