+ 1
What is the difference between append() and appendTo() in jQuery?
Both definition seems to add contents at the end of the selected elements.
2 odpowiedzi
+ 3
The difference between append() and appendTo() is in how (in wich order) parameters are passed:
// given:
var targetElement = $('.myclass');
var newElement = $('<div>content to append</div>');
// both above are equivalent:
targetElement.append(newElement);
newElement.appendTo(targetElement);
+ 2
Thanks.
In terms of adding new elements, they works the same, only the syntax is different.
However, there is one difference, appendTo() can move elements around.
Check out the code below for example.
I have been exploring the code for a bit in code playground.
https://code.sololearn.com/Wjsej1Y1VqGr