jQuery

jQuery Intro

jQuery Intro Quiz

jQuery Intro Exercise

jQuery Basic

jQuery Basic Quiz

jQuery Basic Exercise

jQuery Advance

jQuery Advance Quiz

jQuery Advance Exercise

jQuery Selectors

jQuery Effects

jQuery Events

jQuery Methods and Properties

jQuery Traversing

jQuery CSS and HTML Methods

append() and prepend() in jQuery

append() and prepend() Methods

 

 

As we know that html()  and text() methods are used to get and set the content of any element. However, the main problem arises when we set the content in them. The data will be lost as we set content in elements using these methods. So, for this purpose, we have to use append() and prepend() methods.

 

append():-

 

In append() method the content will be added at the end of the current element.

 

Syntax:-

 

Its syntax is:- $(selector).append(content, function(index,html))

 

Further Explanation:-

 

Parameter Description
content Required. Specifies the content to insert.
function(index,html) Optional. Specifies a function that returns the content to insert
  • index - Returns the index position of the element in the set
  • html - Returns the current HTML of the selected element

 

prepend():-

 

In prepend() the content will be added at the start of the given element.

 

Syntax:-

 

Its syntax is:- $(selector).prepend(content, function(index, html))

 

Further Explanation:-

 

Parameter Description
content Required. Specifies the content to insert.
function(index,html) Optional. Specifies a function that returns the content to insert
  • index - Returns the index position of the element in the set
  • html - Returns the current HTML of the selected element

Code Explanation

All Tutorials related to jQuery Basic

All Sections related to jQuery