返回值:jqueryprepend(content)
概述
向每个匹配的元素内部前置内容。
这是向所有匹配元素内部的开始处插入内容的最佳方式。
参数
contentstring, element, jqueryv1.0
要插入到目标元素内部前端的内容
function(index, html)functionv1.4
返回一个html字符串,用于追加到每一个匹配元素的里边。接受两个参数,index参数为对象在这个集合中的索引值,html参数为这个对象原先的html值。
示例
描述:
向所有段落中前置一些html标记代码。
html 代码:
<p>i would like to say: </p>
jquery 代码:
$("p").prepend("<b>hello</b>");
结果:
[ <p><b>hello</b>i would like to say: </p> ]
描述:
将一个dom元素前置入所有段落
html 代码:
<p>i would like to say: </p>
<p>i would like to say: </p>
<b class="foo">hello</b>
<b class="foo">good bye</b>
jquery 代码:
$("p").prepend( $(".foo")[0] );
结果:
<p><b class="foo">hello</b>i would like to say: </p>
<p><b class="foo">hello</b>i would like to say: </p>
<b class="foo">hello</b>
<b class="foo">good bye</b>
描述:
向所有段落中前置一个jquery对象(类似于一个dom元素数组)。
html 代码:
<p>i would like to say: </p><b>hello</b>
jquery 代码:
$("p").prepend( $("b") );
结果:
<p><b>hello</b>i would like to say: </p>