Archive for the ‘Internet Explorer’ Category

Deleting element properties in Internet Explorer

We have a widget system on the frontend of webmail that allows us to use a factory() method and a destroy() method to avoid memory leaks. I recently wrote a Menu widget that saves data about each item in a property on the element called “_item”. Since this is a custom property I don’t need to keep it once the menu is hidden, I want to remove it for memory leak purposes.

The following code works like a charm:

delete element._item;

Except in Internet Explorer. Apparently IE doesn’t like people deleting properties off of elements. So I came up with this solution:

try {
    delete element._item;
} catch (e) {
    element.removeAttribute('_item');
}

This works great without erroring, but I don’t know if it actually has the same memory implications. Does anyone know?

April 12th, 2007 · Tags Javascript, Development, Internet Explorer | 1 Comment »