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:
$(content).appendTo(selector)
Example of jQuery append To method
Let’s take an example to demonstrate jQuery appendTo() method.
- <!DOCTYPE html>
- <html>
- <head>
- <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
- <script>
- $(document).ready(function(){
- $("button").click(function(){
- $("<span><b>Hello javatpoint.com</b></span>").appendTo("p");
- });
- });
- </script>
- </head>
- <body>
- <button>Add new content at the end of each p element</button>
- <p>I am a new reader.</p>
- <p>I am also a new reader.</p>
- </body>
- </html>
Leave a Reply