What is the prepend() method in jQuery?

In jQuery, the prepend() method is used to insert content at the beginning of the selected elements in the jQuery collection.

Syntax


(a).prepend(b)

Where:

  • a: the element to which the new element will be prepended.

  • b: the content to be prepended.

Code

In the code below, the text Educative rocks! gets added before the p element of the page, which is Learn about Prepend in Jquery. In our case, the text is added once the Prepend Text button is clicked.

Free Resources