Total Page Preview:   000000000138

What is clone() and remove() jQuery?

jQuery clone() and remove()

In jQuery, the clone() method is used to create a copy of the selected elements, including all their descendants and attributes. The remove() method, on the other hand, is used to remove the selected elements from the DOM (Document Object Model).

Let's look at an example that demonstrates the use of clone() and remove():
In this example:
  1. The page contains an original element with a class of "original" and two buttons: "Clone" and "Remove."
  2. When the "Clone" button is clicked, the clone() method is used to create a copy of the original element ($('.original')). The cloned element is then given a class of "cloned" and appended after the original element.
  3. When the "Remove" button is clicked, the remove() method is used to remove the last cloned element with the class "cloned."
This example allows you to clone and remove elements dynamically when interacting with the buttons. You can customize it further based on 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



Comments