Node.prototype.contains

时间:2023-03-09 14:43:12
Node.prototype.contains
document.documentElement.contains(document.body) // true
document.documentElement.compareDocumentPosition(document.body) //
//safari5+是把contains方法放在Element.prototype上而不是Node.prototype
if (!DOC.contains) {
Node.prototype.contains = function (arg) {
return !!(this.compareDocumentPosition(arg) & 16)
}
}
avalon.contains = function(root, el) {
try {
while ((el = el.parentNode))
if (el === root)
return true
return false
} catch (e) {
return false
}
}

Node.prototype.contains