jQuery Document Manipulation - prependTo() Method
Example
Insert content at the beginning of each p element:
$(".btn1").click(function(){ $("<b>Hello World!</b>").prependTo("p"); });
Definition and Usage
The prependTo() method inserts the specified content at the beginning of the selected element (still located internally).
Tip:prepend() Similar in function to the prependTo() method. The difference lies in the syntax: the position of content and selector, as well as the ability of prepend() to use a function to insert content.
Syntax
content).prependTo(selector)
Parameters | Description |
---|---|
content | Required. Specifies the content to be inserted (can include HTML tags). |
selector | Required. Specifies where to insert content. |