Exemple avec jQuery append () et appendTo ()

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 box
I'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 box
I'm new box by prepend
I'm a big box 2
I'm new box by prepend

Essayez-le vous-même









  

jQuery append() and appendTo example

I'm a big box
I'm a big box 2