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:

snippet
$(content).appendTo(selector)

Example of jQuery appendTo() method

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

snippet
<!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 rookienerd.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>
Related Tutorial
Follow Us
https://www.facebook.com/Rookie-Nerd-638990322793530 https://twitter.com/RookieNerdTutor https://plus.google.com/b/117136517396468545840 #
Contents +