0 votes
in JQuery by
Differentiate among .empty() vs .remove() vs .detach() in jQuery.

1 Answer

0 votes
by
remove(): removes the element as well as its child elements. Data from DOM can be restored; however, event handlers can’t be restored.

empty(): does not remove the element; however, remove its content, and the associated child elements

detach(): removes the element and all the associated child elements, but retains the data and event handlers of the removed element to be reused later.

Example usage:

$(“#div-element”).remove();

$(“#div-element”).empty();

$(“#div-element”).detach();
...