jQuery appendTo()

Education is not limited to just classrooms. It can be gained anytime, anywhere... - Ravi Ranjan (M.Tech-NIT)

jQuery appendTo()

The appendTo() method is used to add additional content at the end of the selected elements. It is same as jQuery append() method. There is only syntactical difference between append() and appendTo() methods.

Syntax:

  1. $(content).appendTo(selector)   

Example of jQuery appendTo() method

Let's take an example to demonstrate jQuery appendTo() method.

  1. <!DOCTYPE html>  
  2. <html>  
  3. <head>  
  4. <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>  
  5. <script>  
  6. $(document).ready(function(){  
  7.     $("button").click(function(){  
  8.         $("<span><b>Hello javatpoint.com</b></span>").appendTo("p");  
  9.     });  
  10. });  
  11. </script>  
  12. </head>  
  13. <body>  
  14. <button>Add new content at the end of each p element</button>  
  15. <p>I am a new reader.</p>  
  16. <p>I am also a new reader.</p>  
  17. </body>  
  18. </html>  

Test it Now