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.

New on Educative
Learn to Code
Learn any Language as a beginner
Develop a human edge in an AI powered world and learn to code with AI from our beginner friendly catalog
🏆 Leaderboard
Daily Coding Challenge
Solve a new coding challenge every day and climb the leaderboard

Free Resources