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