Insertion and Deletion Methods

The methods described here insert, delete, and replace document content. In the method signatures below, the content argument may be a jQuery object, a string of HTML, or an individual document element, and the target argument may be a jQuery object, an individual document element, or a selector string. See Getting and Setting Element Content and Chapter 3 for further details.

after(content)after(f(idx):content)

Insert content after each selected element, or invoke f as a method of—and insert its return value after—each selected element.

append(content)append(f(idx,html):content)

Append content to each selected element, or invoke f as a method of—and append its return value to—each selected element.

appendTo(target):jQuery

Appends the selected elements to the end of each specified target element, cloning them as necessary if there is more than one target.

before(content)before(f(idx):content)

Like after(), but make insertions before the selected elements.

clone([data=false]):jQuery

Makes a deep copy of each of the selected elements and returns a new jQuery object representing the cloned elements. If data is true, also clones the data (including event handlers) associated with the selected elements.

detach([sel])

Like remove(), but does not delete any data associated with the detached elements.

empty()

Deletes the content of all selected elements.

html():stringhtml(htmlText)html(f(idx,current):htmlText)

With no arguments, return the content of the first selected ...

Get jQuery Pocket Reference now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.