Skip to content

Instantly share code, notes, and snippets.

@mcbrwr
Created March 15, 2014 07:24
Show Gist options
  • Save mcbrwr/9563003 to your computer and use it in GitHub Desktop.
Save mcbrwr/9563003 to your computer and use it in GitHub Desktop.
Check if thing is node or dom element
//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