Created
March 15, 2014 07:24
-
-
Save mcbrwr/9563003 to your computer and use it in GitHub Desktop.
Check if thing is node or dom element
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Returns true if it is a DOM node | |
function isNode(o){ | |
return ( | |
typeof Node === "object" ? o instanceof Node : | |
o && typeof o === "object" && typeof o.nodeType === "number" && typeof o.nodeName==="string" | |
); | |
} | |
//Returns true if it is a DOM element | |
function isElement(o){ | |
return ( | |
typeof HTMLElement === "object" ? o instanceof HTMLElement : //DOM2 | |
o && typeof o === "object" && o !== null && o.nodeType === 1 && typeof o.nodeName==="string" | |
); | |
} | |
// source: http://stackoverflow.com/questions/384286/javascript-isdom-how-do-you-check-if-a-javascript-object-is-a-dom-object |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment