This article mainly introduces relevant information on the difference between jquery append and appendTo methods. Friends who need it can refer to it. I hope it can help everyone.
The difference between append and appendTo methods in jquery
1. append(content) method
Method function:To each Appends content inside the matching element.
Parameter introduction: content (
Usage example:
HTML code is
I come from
I love
Append a word china to all p tags, the writing method is $("p").append("china");
The result is:
I come from china
I love china2. appendTo(expr) method
Method function:Append all matching elements into the specified collection of elements.
Parameter introduction: expr (String): jQuery expression used to match elements.
Usage example:
HTML code isI love china
Append tag b to p element, written as $("b").appendTo("p");
The result is:>
I love china < /b>
Using the appendTo method reverses the conventional $(A).append(B) operation, that is, instead of appending B to A, appending A to B in.
Related recommendations:
Problems in using the Jquery append method
jquery insertBefore(), insertAfter(), Detailed explanation of prependTo(), appendTo() usage
The difference between jquery append() method and html() method and introduction to their use
The above is the detailed content of jquery append and appendTo usage analysis. For more information, please follow other related articles on the PHP Chinese website!