jQuery appendTo()
jQuery appendTo() is a method that allows the user to append an element to another element. It is a simple and efficient way to manipulate the DOM (Document Object Model) and can be used to dynamically add content to a webpage.
Syntax
The syntax for jQuery appendTo() is as follows:
$(selector).appendTo(target)
Where selector
is the element to be moved, and target
is the element to which it will be appended.
Use
The appendTo() method is used to insert HTML content at the end of a selected element. It is especially useful for dynamic web pages where new content needs to be added dynamically and in real-time without refreshing the page.
Example
Suppose we want to move a list item from one list to another list when a button is clicked. We can achieve that using the following code: