jquery中append和appendto的区别

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了jquery中append和appendto的区别相关的知识,希望对你有一定的参考价值。

1、append()方法:在被选元素的结尾(但仍在元素内部)插入指定的内容。
$(selector).append(content);
append能够使用函数给被选元素附加内容,语法为:
$(selector).append(function(index,html));

2、appendto()方法:在被选元素的结尾(但仍在元素的内部)插入指定的内容。但不能使用函数来附加内容。
$(content).appendto(selector);
参考技术A 在后面追加节点,和把节点追加到某个元素 参考技术B 这有个朋友回答的不错,我引用一下,你看看,应该很好理解的
http://zhidao.baidu.com/link?url=SbCQSHA8x_lc9cKUE-gkcEClsQ9FRPSfaRJTkjgwYgaeTM751aRDVoym80Zaio36hH8f5b61LBhDxbsd2g8OTvBFaiJlBbuOzgaaTA3RRnm

markdown jQuery .clone(),. append(),. appendTo()

## jQuery `clone`

* Used to duplicate a jQuery item:

```
<div class="container">
  <div class="goodbye">
  </div>
</div>
```

* to clone `div.goodbye`: `$('.goodbye').clone();`
* While `clone` creates a **deep** copy of the item (including all children and other nested
elements), it **does not clone event handlers attached to the item!**
* To allow for this behavior, you must make `true` the parameter `withDataAndEvents`,
which is defaulted to false.

```
.clone([withDataAndEvents])
.clone(true)
```

---

## `append` **vs** `appendTo`
* Both these functions perform the same operation: **adding** something to someplace
* They differ in the order of the addition:
    * `append`'s syntax is as follows:
  
        ```
        A.append('B')
        ```
        
        * Take something that **already exists** and add it something new
    * `appendTo`'s syntax differs as follows:
        
        ```
        B.appendTo('A')
        ```
        
        * Take something **new** and add it to something that already exists
        
    

以上是关于jquery中append和appendto的区别的主要内容,如果未能解决你的问题,请参考以下文章

JQuery之append和appendTo的区别,还有js中的appendChild用法

JQuery之append和appendTo的区别,还有js中的appendChild用法

jquery中append与appendTo方法区别

jquery中append()与appendto()用法分析

jquery after append appendTo三个函数的区别

jQuery中append appendTo prepend prependTo insertBefore insertAfter after before之间的区别