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

向每个匹配的元素内部追加内容。 这个操作与对指定的元素执行appendChild方法,将它们添加到文档中的情况类似。

返回值:jQuery

参数:

  • content (<Content>): 要追加到目标中的内容
 
示例:

向所有段落中追加一些HTML标记。

$("p").append("<b>Hello</b>"); 

HTML 代码:

<p>I would like to say: </p>

结果:

<p>I would like to say:   <b>Hello</b></p>
示例:

向所有段落中追加一个元素。

$("p").append( $("#foo")[0] ); 

HTML 代码:

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

结果:

<p>I would like to say: <b   id="foo">Hello</b></p>
示例:

向所有段落中追加一个jQuery对象(类似于一个DOM元素数组)。

$("p").append( $("b") ); 

HTML 代码:

<p>I would like to say:   </p><b>Hello</b>

结果:

<p>I would like to say:   <b>Hello</b></p>
 
append( content )

Append content to the inside of every matched element.

This operation is similar to doing an appendChild to all the specified elements, adding them into the document.

Return value: jQuery
Parameters:

  • content (<Content>): Content to append to the target
 

Example:

Appends some HTML to all paragraphs.
$("p").append("<b>Hello</b>");

Before:

<p>I would like to say: </p>

After:

<p>I would like to say: <b>Hello</b></p>

Example:

Appends an Element to all paragraphs.

$("p").append( $("#foo")[0] );

Before:

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

After:

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

Example:

Appends a jQuery object (similar to an Array of DOM Elements) to all paragraphs.

$("p").append( $("b") );

Before:

<p>I would like to say: </p><b>Hello</b>

After:

<p>I would like to say: <b>Hello</b></p>