Append appendchild appendto Difference

Source: Internet
Author: User

The difference between 1.append and appendchild

Append is a jquery document operation usage

The ①append () method inserts the specified content at the end of the selected element (still inside).

$ (selector). Append (content)
1 $ ("button"). Click (function () {2   <b>Hello world!  </b>"); 3 });

② uses a function to insert content at the end of a specified element.

$ (selector). Append (function (index,html))
1 $ (document). Ready (function () {2  $ ("button"). Click (function () {3     $ ("P"). Append (function (n) {4       return "<b>this P element have Index "+ n +"</b>"; 5     }); 6   }); 7 });

AppendChild

The AppendChild () method adds a node after the last child node of the specified element node.

The method returns a new child node.

AppendChild (node)
1     <DivID= "Div1">Look back always bleak place, return, also no wind and rain also no clear</Div>2     <Scripttype= "Text/javascript">3         varop=Document.createelement ('P');4         varOdiv=document.getElementById ('Div1');5 op.innerhtml="Oh , yes.";6 odiv.appendchild (OP);7     </Script>

return result is

<div id= "div1"> Look back always bleak place, return, also no wind and rain also no clear<p> Yes, </p> . </div> the P node is returned2.append and Appendto AppendToThe AppendTo () method inserts the specified content at the end of the selected element (still inside).
$ (content). AppendTo (selector)
$ ("button"). Click (function () {  $ ("<b>Hello world!  </b>"). AppendTo (" P ");});

Append and Appendto are all uses of jquery, so the elements before append or appendto must be jquery objects.

$ ("P"). Append ("<a>111</a>") is equivalent to $ ("<a>111</a>"). AppendTo ($ ("P");

Append appendchild appendto Difference

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.