tableau-mkt/jquery.addressfield

View on GitHub
src/jquery.detach-polyfill.js

Summary

Maintainability
A
0 mins
Test Coverage
/**
 * Polyfill for .detach(), jQuery < 1.4
 *
 * The .detach() method is the same as .remove(), except that .detach() keeps
 * all jQuery data associated with the removed elements. This method is useful
 * when removed elements are to be reinserted into the DOM at a later time.
 *
 * Remove when support for jQuery 1.3 is dropped.
 */
(function ($) {
  /* istanbul ignore next */
  if (!$.fn.detach) {
    $.fn.detach = function (selector) {
      for (var i = 0, elem; (elem = this[i]) != null; i++) {
        if (!selector || jQuery.filter(selector, [elem]).length) {
          if (elem.parentNode) {
            elem.parentNode.removeChild(elem);
          }
        }
      }

      return this;
    };
  }
}(jQuery));