jQuery API jQuery API 中英文对照版 - jQuery在线查询手册
appendTo(expr)
appendTo(expr)

把所有匹配的元素追加到另一个、指定的元素元素集合中。实际上,使用这个方法是颠倒了常规的$(A).append(B)的操作,即不是把B追加到A中,而是把A追加到B中。

返回值:jQuery

参数:

  • expr (String): 用于匹配元素的jQuery表达式
 

示例:

把所有段落追加到ID值为foo的元素中。

$("p").appendTo("#foo"); 

HTML 代码:

<p>I would like to say: </p><div   id="foo"></div>

结果:

<div id="foo"><p>I would like to say:   </p></div>
 
appendTo( content )

Append all of the matched elements to another, specified, set of elements. This operation is, essentially, the reverse of doing a regular $(A).append(B), in that instead of appending B to A, you're appending A to B.

Return value: jQuery
Parameters:

  • content (<Content>): Content to append to the selected element to.
 

Example:

Appends all paragraphs to the element with the ID "foo"

 $("p").appendTo("#foo");  
Before:
 <p>I would like to say: </p><div id="foo"></div>  
Result:
 <div id="foo"><p>I would like to say: </p></div>