返回值:jqueryinsertbefore(content)
概述
把所有匹配的元素插入到另一个、指定的元素元素集合的前面。
实际上,使用这个方法是颠倒了常规的$(a).before(b)的操作,即不是把b插入到a前面,而是把a插入到b前面。
在jquery 1.3.2中,appendto, prependto, insertbefore, insertafter, 和 replaceall这个几个方法成为一个破坏性操作,要选择先前选中的元素,需要使用end()方法,参见 appendto 方法的例二。
参数
contentstringv1.0
用于匹配元素的jquery表达式
示例
描述:
把所有段落插入到一个元素之前。与 $("#foo").before("p")相同。
html 代码:
<div id="foo">hello</div><p>i would like to say: </p>
jquery 代码:
$("p").insertbefore("#foo");
结果:
<p>i would like to say: </p><div id="foo">hello</div>