contains.js 345 B

1234567891011121314151617181920
  1. export default function contains(root, n) {
  2. if (!root) {
  3. return false;
  4. }
  5. // Use native if support
  6. if (root.contains) {
  7. return root.contains(n);
  8. }
  9. // `document.contains` not support with IE11
  10. var node = n;
  11. while (node) {
  12. if (node === root) {
  13. return true;
  14. }
  15. node = node.parentNode;
  16. }
  17. return false;
  18. }