contains.js 438 B

1234567891011121314151617181920212223242526
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.default = contains;
  6. function contains(root, n) {
  7. if (!root) {
  8. return false;
  9. }
  10. // Use native if support
  11. if (root.contains) {
  12. return root.contains(n);
  13. }
  14. // `document.contains` not support with IE11
  15. var node = n;
  16. while (node) {
  17. if (node === root) {
  18. return true;
  19. }
  20. node = node.parentNode;
  21. }
  22. return false;
  23. }