jQuery - méthode appendto (selector)

La description

le appendTo( selector ) La méthode ajoute tous les éléments correspondants à un autre ensemble d'éléments spécifié.

Syntaxe

Voici la syntaxe simple pour utiliser cette méthode -

selector.appendTo( selector )

Paramètres

Voici la description de tous les paramètres utilisés par cette méthode -

  • selector - C'est la cible à laquelle le contenu sera ajouté.

Exemple

Voici un exemple simple montrant l'utilisation de cette méthode -

<html>
   <head>
      <title>The jQuery Example</title>
      <script type = "text/javascript" 
         src = "https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js">
      </script>
		
      <script type = "text/javascript" language = "javascript">
         $(document).ready(function() {
            $("div").click(function () {
               $(this).appendTo("#result");
            });
         });
      </script>
		
      <style>
         .div{ margin:10px;padding:12px; border:2px solid #666; width:60px;}
      </style>
   </head>
	
   <body>
      <p>Click on any square below to see the result:</p>
      <p id = "result"> THIS IS TEST </p>
      <hr />
		
      <div class = "div" style = "background-color:blue;"></div>
      <div class = "div" style = "background-color:green;"></div>
      <div class = "div" style = "background-color:red;"></div>
   </body>.
</html>

Cela produira le résultat suivant -

jquery-dom.htm