Exemple avec jQuery append () et appendTo ()
Les méthodes jQueryappend() etappendTo() font la même tâche, ajoutent un contenu texte ou html après le contenu des éléments correspondants. La principale différence réside dans la syntaxe.
Par exemple,
I'm a big boxI'm a big box 2
1. $(‘selector’).append(‘new text’);
$('.box').append("I'm new box by prepend");
2. $(‘new text’).appendTo(‘selector’);
$("I'm new box by appendTo").appendTo('.box');
Résultat
Les deux méthodes ci-dessus font la même tâche, mais avec une syntaxe différente, le nouveau contenu aprèsappend() ouappendTo() deviendra
I'm a big boxI'm new box by prependI'm a big box 2I'm new box by prepend
Essayez-le vous-même
jQuery append() and appendTo example
I'm a big boxI'm a big box 2