Introduction:

In this article we will explain how to add specified content at the end of the selected element in jquery or What is appendTo() method in jquery or why use appendTo() method in jquery with example.

Description:

jQuery appendTo() method is used to insert 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.

To insert content at the beginning of the selected elements, use the prependTo() method.

Syntax:

$(content).appendTo(selector)

Let’s see, Example of jQuery appendTo() method:

<!DOCTYPE html>
<html>
<head>
    <title>Example of jQuery appendTo method</title>
    <script type="text/javascript" src="https://code.jquery.com/jquery-1.10.2.js"></script>
    <script>
        $(document).ready(function () {
            $("button").click(function () {
                $("<span><b>www.sqltutorialspoint.com</b></span>").appendTo("div");
            });
        });
    </script>
</head>
<body>
    <button>Add new content at the end of each div element</button>
    <div>This is tutorials website for learning new technologies.</div>
</body>
</html>


 Let's check live example

comments


Leave a comment

Make sure you enter the (*) required information where indicated. HTML code is not allowed.

You may also like