93
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:
|
Function (index, html) | It is an optional parameter. It specifies a function that returns the content which is inserted.
|
Example of jQuery prepend() method
Let’s take an example to demonstrate the jQuery prepend() method.
Output:
This is the first paragraph.
This is the second paragraph.
jQuery prepend() example 2
Output:
This is the first paragraph.
This is the second paragraph.
- Item no.1
- Item no.2
- Item no.3
jQuery prepend() example 3
Output:
Hello tutoraspire.com
Hello Guys! Welcome to the best tutorial site.
Here, "Hello" is the prepended text.
Next TopicjQuery after()