Learning this chapter in the jquery authoritative guide, it is necessary to introduce the contents:
The first is the append (content) function:
It means adding content to the contents of the selected object.
For example: $ ("div"). Append ("<p>" + Hello + "</p>");
Add a P tag to all DIV elements, the tag content is Hello, and if there is other content inside the div element, add new content after the original content
Then there is the appendto (content) function:
By the word "to" we will know what this function means to add to what, so it is the biggest difference with the append () function:
The location of content and selectors, and append () can use functions to attach content. and the tasks they perform are the same.
As the above example:
$ ("div"). Append ("<p>" + Hello + "</p>"); add P tag to all div in page
If you use Appendto, you should write this:
$ ("<p>" + Hello + "</p>"). AppendTo ("div")
There's another form of append.
Append (function (index,html) {})
The usage is the same as the original append, but the index and HTML in the function do not take for granted that it is inserted under the first index Div HTML content, in fact, these two parameters are only used to return the current object's index value and the original content
jquery Code
$ (function() { $ ("div"). Append (function(n,m) { return "Hello" + "index value:" + N + "original content:" + m; }); })
HTML code
<P>Hello</P> <Div>JQuery 1</Div> <Div>JQuery 2</Div> <Div>JQuery 3</Div> <Div>JQuery 4</Div>
Browser results:
The usage of prepend and prependto is the same as that of append,appendto, except that prepend and prependto Add new content in front of the selected object content.
JQuery append,appendto,prepend,prependto Introduction