Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

jQuery prepend() method

jQuery prepend() method

jQuery HTML/CSS methods jQuery HTML/CSS methods

Example

Toggle between slideUp() and slideDown() on all

Insert content at the beginning of the element:

$

(

"

button

"

)

.

click

(

function

(

)

{

$

(

"

p

"

)

.

prepend

(

"

Prepended text

"

)

;

}

)

;

Try it »


Definition and Usage

The prepend() method inserts the specified content at the beginning of the selected elements.

**Tip:** To insert content at the end of the selected elements, use append() method.


Syntax

$(

selector

).prepend(

content

,function

(index,html)

)

Parameters Description
content Required. Specifies the content to insert (may contain HTML tags).

Possible values:

  • HTML element
  • jQuery object
  • DOM element
  • | | function*(index,html)* | Optional. Specifies a function that returns the content to insert. |

    More examples

    prepend() - creating content with HTML, jQuery, and DOM
    Inserting content with the prepend() method.

    Prepending content using a function
    Use a function to insert content at the beginning of the selected elements.


    jQuery HTML/CSS methods jQuery HTML/CSS methods