jquery append () and appendto () deep learning __jquery

Source: Internet
Author: User

Although the previous write Jquerydom operation-based on the command to change the page, the two methods have been learned,

However, today when the car reading, found append () and appendto () the difference, I unexpectedly can't remember. Helpless, continue to learn.

Only after the deep study can let oneself remember the more solid, otherwise oneself this often selectively forgets some things of head still really can't remember what.

Let's take a look at the instructions above in the API to help us better understand these two methods:

Append (content)

Appends content to each matching element.

This action is similar to the way that the AppendChild method is executed on the specified elements and added to the document.

Appendto (content)

Appends all matching elements to another, specified set of element elements.

In fact, using this method reverses the normal $ (A). Append (b) operation, that is, instead of appending B to a, append a to B.


This seems to have been said very clear, but not through the example, how can I understand so deep.         Oh. Append (content)

Append content to <font color= ' red ' > each matching element </font> internal.
<br/>
This action is similar to the way that the AppendChild method is executed on the specified elements and added to the document.

<br/>
<p class= ' append_p ' >welcome </p>

<p class= ' append_p ' > Welcome </p>

<input type= ' button ' id= ' Append_button ' value= ' append '

<br/>
Appendto (content)

Append <font color= ' red ' > All matching elements </font> to another, specified set of element elements.
<br/>
In fact, using this method reverses the normal $ (A). Append (b) operation, that is, instead of appending B to a, append a to B.

<br/>
<p class= ' appendto_p ' >welcome </p>

<p class= ' appendto_p ' > Welcome </p>

<input type= ' button ' id= ' Appendto_button ' value= ' appendto ' sample '/> $ (document). Ready (function () {
$ (' #append_button '). Click (function () {
$ (' p.append_p '). Append (' <b><a href= "http://www.xiaoxiaozi.com/" target= "_blank" >xiaoxiaozi.com</a></b> ") ;
} ) ;

$ (' #appendto_button '). Click (function () {
$ (' <b><a href= ' http://www.xiaoxiaozi.com/' target= ' _blank ' >xiaoxiaozi.com</a></b> '). Appendto (' p.appendto_p ');
} ) ;
} ) ;

Oh, see the results. This is the case:

Append () is preceded by the object to select, followed by the element content to be inserted inside the object

Appendto () is preceded by the element content to be inserted, followed by the object to be selected

Apply what wangsong76 says:

But $ ("P"). Append ("arbitrary string"); and $ ("any string"). Appendto ("P"); Are these two operations equivalent?

is not a simple equivalence, is conditional. Well.

But unlike what Wangsong76 said, it's the difference between IE and Firefox, and I don't think so.

For example: The HTML section is the same as in the previous example, and we'll change the JS section $ (document). Ready (function () {
$ (' #append_button '). Click (function () {
$ (' p.append_p '). Append (' xiaoxiaozi.com ');
} ) ;

$ (' #appendto_button '). Click (function () {
$ (' xiaoxiaozi.com '). Appendto (' p.appendto_p ');
} ) ;
} ) ;

See it. The second function has no effect. The reason is what.

I feel like I should be in jquery. $ (' pure string, non-HTML statement or object ') cannot be used as a jquery object. This is a reprint of an article, the following are reproduced address. The last word is the reason I reprint, is the essence of the blog.

Article Author: simaopig
This article address: http://www.xiaoxiaozi.com/2009/05/31/694/
Copyright © reproduced must be linked to the form of the author and the original source.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.