How to check if object DOM element
/**
* Check is object a DOM element
*
* ... usage ...
* // isDomElement( element )
*
* @param elem
* @returns {boolean|*}
*/
const isDomElement = (elem = null) => {
try {
if (typeof elem === "string" && elem != "") {
elem = document.querySelector('#' + elem);
}
if (typeof elem === "undefined" || elem == null) {
return false;
}
throw "Parameter is not a number!";
} catch (e) {
return (typeof HTMLElement === "object" ? elem instanceof HTMLElement : elem != "" && typeof elem === "object" && elem !== null && elem.nodeType === 1 && typeof elem.nodeName === "string" && typeof elem.ownerDocument === "object" && elem);
}
};
Written by david262929
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Objects javascript isdomelement html dom
Authors
Related Tags
#objects javascript isdomelement html dom
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#