naive-ui/packages/utils/dom/getParentNode.js

13 lines
305 B
JavaScript
Raw Normal View History

2019-07-11 19:51:59 +08:00
/**
* Returns the parentNode or the host of the element until document
2019-07-11 19:51:59 +08:00
* @method
* @param {Element} element
* @returns {Element} parent
*/
export default function getParentNode (element) {
if (element.nodeName === '#document') {
2019-07-11 19:51:59 +08:00
return element
}
return element.parentNode || element.host
}