2

Secrets of the JavaScript Ninja demonstrates the following code to remove an HTML element:

  function remove() {
    // Go through all descendants and the element to be removed
    jQuery("*", this).add([this]).each(function () {
      // Remove all bound events
      jQuery.event.remove(this);

      // Remove attached data
      jQuery.removeData(this);
    });

    // Remove the element (if it's in the DOM)
    if (this.parentNode)
      this.parentNode.removeChild(this);
  }

If jQuery.event.remove(this) were commented out, would a memory leak occur? Meaning, if an event is tied to an element, but then the element (but not its events) are removed, what will happen?

Kevin Meredith
  • 41,036
  • 63
  • 209
  • 384

0 Answers0