Code has been added to clipboard!

Using jQuery .append() to Insert Content Into an HTML Element

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

jQuery append: Main Tips

  • The .append() jQuery method inserts content at the end of the selected element as its last child. To add it as the first child, use .prepend().
  • jQuery append() achieves the same result as .appendTo(), but uses different syntax. This is important when using chained statements.

Using .append()

The jQuery .append() inserts content as the last child of the selected element. It means that the specified content will appear inside the selected element's tag but after all other children.

The example below shows that after a button is clicked, additional text appears, which still belongs to the heading:

Example
$("button").click(() => {
    $("h2").append("<p>Surprise text!</p>");
});

The following syntax makes jQuery append HTML:

$("selector").append(content);

  • The selector defines the target element.
  • The content specifies the jQuery object, HTML string, DOM element, text node, or an array to add to it. You can add multiple pieces of content as well.

Note: since jQuery 1.4, you can also name a function as the parameter that will return the content to add.

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