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

jQuery prependTo() method

jQuery prependTo() method

jQuery HTML/CSS methods jQuery HTML/CSS methods

Example

Insert content after each

Insert at the beginning of the element element:

$

(

"

button

"

)

.

click

(

function

(

)

{

$

(

"

Hello World!

"

)

.

prependTo

(

"

p

"

)

;

}

)

;

Try it »


Definition and Usage

The prependTo() method inserts HTML elements at the beginning of the selected elements.

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


Syntax

$(

content

).prependTo(

selector

)

Parameters Description
content Required. Specifies the content to insert (must contain HTML tags).
 **注意:**如果 *content* 是已存在的元素,它将从当前位置被移除,并在被选元素的开头被插入。 |

| selector | Required. Specifies which element to prepend the content to. |


More examples

Inserting existing elements
How to use the prependTo() method to insert existing elements at the beginning of each selected element.


jQuery HTML/CSS methods jQuery HTML/CSS methods