jQuery API | jQuery API 中英文对照版 - jQuery在线查询手册 |
prependTo(expr) |
prependTo(expr)
把所有匹配的元素前置到另一个、指定的元素元素集合中。 实际上,使用这个方法是颠倒了常规的$(A).prepend(B)的操作,即不是把B前置到A中,而是把A前置到B中。 返回值:jQuery 参数:
把所有段落前置到ID值为foo的元素中。 $("p").prependTo("#foo"); HTML 代码: <p>I would like to say: </p><div id="foo"><b>Hello</b></div> 结果: <div id="foo"><p>I would like to say: </p><b>Hello</b></div> Prepend all of the matched elements to another, specified, set of elements. This operation is, essentially, the reverse of doing a regular $(A).prepend(B), in that instead of prepending B to A, you're prepending A to B. Return value: jQuery
Example: Prepends all paragraphs to the element with the ID "foo" $("p").prependTo("#foo");Before: <p>I would like to say: </p><div id="foo"><b>Hello</b></div>Result: <div id="foo"><p>I would like to say: </p><b>Hello</b></div> |