jQuery prepend()メソッド
例
すべての<p>要素の先頭にコンテンツを挿入します。
$("button").click(function(){
$("p").prepend("<b>Prepended text</b>");
});
定義と使用法
prepend()メソッドは、選択した要素の先頭に指定されたコンテンツを挿入します。
ヒント:選択した要素の最後にコンテンツを挿入するには、 append()メソッドを使用します。
構文
$(selector).prepend(content,function(index,html))
Parameter | Description |
---|---|
content | Required. Specifies the content to insert (can contain HTML tags)
Possible values:
|
function(index,html) | Optional. Specifies a function that returns the content to insert
|
自分で試してみてください-例
。prepend()メソッドを使用してコンテンツを挿入します。
を使用して、選択した要素の先頭にコンテンツを挿入します。