Latest web development tutorials

jQuery prepend () method

jQuery HTML / CSS Methods jQuery HTML / CSS Methods

Examples

In all <p> element at the beginning of Inserts:

$("button").click(function(){
$("p").prepend("<b>Prepended text</b>");
});

try it"

Definition and Usage

prepend () method to insert the specified content at the beginning of the selected element.

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


grammar

$(selector).prepend(content,function(index,html))

参数 描述
content 必需。规定要插入的内容(可包含 HTML 标签)。

可能的值:

  • HTML 元素
  • jQuery 对象
  • DOM 元素
function(index,html) 可选。规定返回待插入内容的函数。
  • index- 返回集合中元素的 index 位置。
  • html- 返回被选元素的当前 HTML。


Examples

More examples

prepend () - Create content via HTML, jQuery and DOM
() Method to insert content via prepend.

Use pre-function content
Using the function at the beginning of the selected element insertions.


jQuery HTML / CSS Methods jQuery HTML / CSS Methods