jQuery Add

tutorial and example
tutorial and example

Using the jQuery, it is easy to add new content. Here are four jQuery methods to add new content:

jQuery append() Method

The jQuery append() method is used to insert the content at the end of the selected HTML elements.

Syntax:

Content: Content is a mandatory parameter which is used to specify the content you want to insert. Its possible values can be DOM elements, HTML elements and jQuery objects.

Function: Function is an optional parameter which is used to specify the function that returns the content to insert.

Index: It is used to return the index position of the content.

HTML: It is used to return the current HTML of the selected content.

Example:

Try Now

jQuery prepend() Method

jQuery prepend() method is used to insert the content at the beginning of the selected HTML contents.

jQuery prepend() method is opposite of the jQuery append() method.

Syntax:

Content: Content is a mandatory parameter which is used to specify the content you want to insert. Its possible values can be DOM elements, HTML elements and jQuery objects.

Function: Function is an optional parameter which is used to specify the function that returns the content to insert.

Index: It is used to return the index position of the content.

HTML: It is used to return the current HTML of the selected content.

Example:

Try Now

jQuery after() method

The jQuery after() method is used to insert the content after the selected HTML elements. It is just like jQuery append() method.

Syntax:

Content: Content is a mandatory parameter which is used to specify the content you want to insert. Its possible values can be DOM elements, HTML elements and jQuery objects.

Function: Function is an optional parameter which is used to specify the function that returns the content to insert.

Index: It is used to return the index position of the content.

HTML: It is used to return the current HTML of the selected content.

Example:

Try Now

jQuery before() Method

The jQuery before() method is used to insert the content before the selected HTML elements.

Syntax:

Content: Content is a mandatory parameter which is used to specify the content you want to insert. Its possible values can be DOM elements, HTML elements and jQuery objects.

Function: Function is an optional parameter which is used to specify the function that returns the content to insert.

Index: It is used to return the index position of the content.

Example:

Try Now