把所有匹配的元素插入到另一个、指定的元素元素集合的前面。
实际上,使用这个方法是颠倒了常规的$(A).before(B)的操作,即不是把B插入到A前面,而是把A插入到B前面。
返回值
jQuery
参数
content (String) : 用于匹配元素的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>