What\'s the difference between empty()
and remove()
methods in jQuery
, and when we call any of these methods, the objects being created
The documentation explains it very well. It also contains examples:
before:
Hello
Goodbye
.remove():
$('.hello').remove();
after:
Goodbye
before:
Hello
Goodbye
.empty():
$('.hello').empty();
after:
Goodbye
As far as memory is concerned, once an element is removed from the DOM and there are no more references to it the garbage collector will reclaim the memory when it runs.