jQuery API | 返回首页目录 | jQuery API 中英文对照版 |
insertBefore(expr) |
insertBefore(expr)
把所有匹配的元素插入到另一个、指定的元素元素集合的前面。 实际上,使用这个方法是颠倒了常规的$(A).before(B)的操作,即不是把B插入到A前面,而是把A插入到B前面。 返回值:jQuery 参数:
示例: 与 $("#foo").before("p")相同 $("p").insertBefore("#foo"); HTML 代码: <div id="foo">Hello</div><p>I would like to say: </p> 结果: <p>I would like to say: </p><div id="foo">Hello</div> insertBefore( content ) Insert all of the matched elements before another, specified, set of elements. This operation is, essentially, the reverse of doing a regular $(A).before(B), in that instead of inserting B before A, you're inserting A before B. Return value: jQuery
Example: Same as $("#foo").before("p") $("p").insertBefore("#foo");Before: <div id="foo">Hello</div><p>I would like to say: </p>Result: <p>I would like to say: </p><div id="foo">Hello</div> |