Home >>jQuery Tutorial >jQuery appendTo() Method

jQuery appendTo() Method

jQuery appendTo() Method

jQuery appendTo() method is used to inserts HTML elements at the end of the selected elements.

Syntax:
$(content).appendTo(selector)

Parameter Values

Parameter Description
content It is a Required parameter and is used to insert the Specifies the content (must contain HTML tags).
selector It is Required parameter used to Specifies to append the content of selected element
Here is an Example of jQuery appendTo() Method:

<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$(".btn1").click(function(){
$("<span>Hello phptpoint!</span>").appendTo(".txt1");
});
});
</script>
</head>
<body>
<button class="btn1">click me to insert element</button>
<p class="txt1">This is a paragraph...</p>
<p class="txt1">PHPTPOINT...</p>
</body>
</html>

Output:

This is a paragraph...

PHPTPOINT...


No Sidebar ads