http://stackoverflow.com/questions/384286/ javascript-isdom-how-do-you-check-if-a-javascript-object-is-a-dom-object/27112297#27112297
To determine the node type:
<Body> <DivID= "Test">Aaa</Div> <!--This is a comment node - <Script> variselement= function(EL) {return !!El&&El.nodetype=== 1;//pay attention to this return and!! El's Judgment } vara={nodeType:1} console.log (Iselement (document.getElementById ("Test"))); Console.log (Iselement (document.getElementById ("Test"). nextSibling)); Console.log (Iselement (a)); </Script></Body>
A more rigorous approach to judgment
<Body> <DivID= "Test">Aaa</Div> <!--This is a comment node - <Script> varTestdiv=Document.createelement ('Div'); variselement= function(obj) {if(obj&&Obj.nodetype=== 1) {//First, filter the simplest if(window. Node&&(objinstanceofNode)) { //if it is IE9, determine if it is an instance of node return true; //because obj may be from another document object, it cannot easily return false } Try {//Finally, this is a very poor efficiency, but certainly feasible scheme to determinetestdiv.appendchild (obj); Testdiv.removechild (obj); } Catch(e) {return false; } return true; } return false; } vara={nodeType:1} console.log (Iselement (document.getElementById ("Test"))); Console.log (Iselement (document.getElementById ("Test"). nextSibling)); Console.log (Iselement (a)); </Script></Body>
dom-determining element node types