jQuery : Are events handlers removed from objects if they are removed from the DOM using html()

后端 未结 2 1359
南旧
南旧 2021-02-15 10:47

I am concerned about memory leaks in my application as I use jquery\'s html() method a lot to replace content in the the DOM. I just want to make sure that not of these

2条回答
  •  一整个雨季
    2021-02-15 11:04

    Yes they are.

    If you use jQuerys .html() it will take care of you. Looking into the jQuery source, this line is getting called:

    jQuery.cleanData( this[i].getElementsByTagName("*") );
    

    which effectively cleans up all data and events. This of course won't work if you're overwritting a DOMnodes innerHTML property explicitly.

提交回复
热议问题