dqhendricks
dqhendricks

Reputation: 19251

Is it necessary to unbind events from elements removed from a document

I am using JQuery, and I would like to know if the remove() method cleans its contents of event handlers. For instance:

function someFunction() {
    var element = $('<div></div>');
    element.click(function() {
        alert('bar');
    });
    $('body').append(element);
    element.remove();
}

At this point is there an event handler still hanging out in memory? If so, is there a way to clear the element object of event handlers before removing it from the DOM?

Upvotes: 5

Views: 183

Answers (1)

Derek Hunziker
Derek Hunziker

Reputation: 13141

According to jquery docs:

In addition to the elements themselves, all bound events and jQuery data associated with the elements are removed.

Upvotes: 8

Related Questions