Comparison between jquery append and appendTo, jqueryappendto
Differences between append and appendTo methods in jquery
1. append (content) Method
Function:Append content to each matching element.
Parameter description: content (<Content>): content to be appended to the target.
Usage example:
The HTML code is <p> I come from </p> <p> I love </p>
Append the word "china" to all p tags and write it as $ ("p"). append ("china ");
Result: <p> I come from china </p> <p> I love china </p>
2. appendTo (expr) Method
Function:Append all matched elements to the specified element set.
Parameter description: expr (String): jQuery expression used to match elements.
Usage example:
The HTML code is <B> I love china </B> <p> </p>
Append Label B to the p element and write it as $ ("B"). appendTo ("p ");
Result: <p> <B> I love china </B> </p>
By using appendTo, the general $ (A). append (B) operations are reversed. That is, B is not appended to A, but A is appended to B.
Thank you for reading this article. I hope it will help you. Thank you for your support for this site!