There is no big difference between those functions except the syntax:
$(\'.target\').append(\'text\');
$(\'text\').appendTo(\'.target\');
A
I think there are two main points to consider:
What do you already have references to? If you already have a jQuery object containing the elements you want to append then it makes sense to use .appendTo()
rather than selecting the elements you want to append to and then using .append()
.
Do you want/need to chain functions? One of the things that jQuery does well is allow you to chain functions together, because every function returns a jQuery object. Obviously if you want to call functions on the elements that you're appending, you'll want to use .appendTo()
so that any functions you chain after that will apply to the elements being appended, not the elements being appended to.