Total Page Preview: 000000000257
What is append() and appendTo() in jQuery?
append() & appendTo() in jQuery
In jQuery, append() and appendTo() are methods used to manipulate the content of HTML elements by adding new elements or content. Let's explore each method with a brief explanation and a single example:
1-append() method:
The append() method is used to insert content, specified by the parameter, to the end of each element in the set of matched elements.
Example:
In this example, the append() method adds a new <p> element with the text "New Content" at the end of the div with the ID "container."
2-appendTo() method:
The appendTo() method does the same thing as append(), but in a different way. It appends the selected elements to the target element(s) instead of appending the target element to the selected one(s).
Example:
In this example, the appendTo() method appends the newly created <p> element with the text "New Content" to the div with the ID "container."
Both examples achieve a similar result, but the choice between append() and appendTo() depends on the preferred syntax and readability in your specific use case.
Thank You
About Author
Brijesh Kumar
Database Developer
I have more then 6 years Experience in Microsoft Technologies - SQL Server Database, ETL
Azure Cloud - Azure SQL Database, CosmosDB, Azure Data Factory, PowerBI, Web Job, Azure Function, Azure Storage, Web Apps, Powershall
and Database Migration On-Premise to Azure Cloud.
LinkedIn : https://www.linkedin.com