jQuery empty() vs remove()

后端 未结 3 1773
孤街浪徒
孤街浪徒 2020-12-12 15:25

What\'s the difference between empty() and remove()methods in jQuery, and when we call any of these methods, the objects being created

3条回答
  •  南方客
    南方客 (楼主)
    2020-12-12 15:52

    The documentation explains it very well. It also contains examples:

    • .remove()
    • .empty()

    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.

提交回复
热议问题