jQuery prepend()

The jQuery prepend() method is used to insert the specified content at the beginning (as a first child) of the selected elements. It is just the opposite of the jQuery append() method.

If you want to insert the content at the end of the selected elements, you should use the append method.

Syntax:

Parameters of jQuery prepend() method

Parameter Description
Content It is a mandatory parameter. It specifies the content which you want to insert. Its possible values are:
  • HTML elements
  • jQuery objects
  • DOM elements
Function (index, html) It is an optional parameter. It specifies a function that returns the content which is inserted.
  • Index:It is used to provide the index position of the element in the set.
  • Html: : It provides the current HTML of the selected element.

Example of jQuery prepend() method

Let's take an example to demonstrate the jQuery prepend() method.

Test it Now

Output:

This is the first paragraph.

This is the second paragraph.

jQuery prepend() example 2

Test it Now

Output:

This is the first paragraph.

This is the second paragraph.

  1. Item no.1
  2. Item no.2
  3. Item no.3

jQuery prepend() example 3

Test it Now

Output:

Hello tutorialsinfo.com

Hello Guys! Welcome to the best tutorial site.

Here, "Hello" is the prepended text.

Next TopicjQuery after()




Contact US

Email:[email protected]

jQuery prepend()
10/30