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) 


Example of jQuery appendTo() method

Let's  see an example of  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>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> 

 

Output:



I hope it will help to you.

0 comments


Leave a comment

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

you may also like