If you want to add some content to the end of the text then jQuery AppendTo function is the same method as jQuery Append function to perform this task.

There is only syntax difference between the jQuery appendTo() and jQuery append().

In jQuery AppendTo method, you have to first provide the content to add at the end of the HTML element then after you can use jQuery selectors to specify and access the HTML element.

Syntax

Sr. No Parameter Name Description
1 content The parameter is used to provide the content you want to add at the end of the selected element. It is the required parameter.
2 selector The parameter is used to select and access the required HTML element to append the content at the end. It is the required parameter.

Example of jQuery AppendTo Function

You can use below given example of jQuery appendTo()

Output


Welcome to the Tutorialdeep jQuery Tutorial to learn appendto.

The above example performs the same task of jQuery append function and add the text to the end of the p element when you click the button.

The same thing you should notice here that when you click the given button for the number of times, appendto function repeats the insertion the text to the end of the content again and again. You just press the button for more than one time and you can see the changes the function made to the content.

Example1: jQuery AppendTo with HTML tags inside the content

Output


This is the jQuery Tutorial to Learn AppendTo Method.

The example given above contains the content to append with three tags span, strong and b. After you click the button, the jQuery appendTo function adds the content to end of the text with the output of these tags.

Now, the same thing you should notice here as you have noted in the first example given above, The more the number of times you click the button, the number of times appendTo function add the content at the end of the paragraph text.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.