Why is it risky to store data as an attribute of an element?

前端 未结 2 1172
灰色年华
灰色年华 2021-02-04 01:35

I keep reading the same thing:

\"Storing property values directly on DOM elements is risky because of possible memory leaks.\"

But c

2条回答
  •  故里飘歌
    2021-02-04 02:25

    According to the jQuery documentation:

    In Internet Explorer prior to version 9, using .prop() to set a DOM element property to anything other than a simple primitive value (number, string, or boolean) can cause memory leaks if the property is not removed (using .removeProp()) before the DOM element is removed from the document. To safely set values on DOM objects without memory leaks, use .data().

提交回复
热议问题