jQuery Document Manipulation - detach() Method
Definition and Usage
The detach() method removes the selected elements, including all text and child nodes.
This method retains the matched elements in the jQuery object, so these elements can be used again in the future.
detach() retains all bound events and attached data, which is different from remove().
Syntax
$(selector).detach()
More examples
- Move an element
- Use the detach() method to move an element.
- Remove and restore an element
- Use the detach() method to remove and restore an element.
- Move an element while retaining its click event
- Use the detach() method to move an element while retaining the jQuery data.