dom - 12 种节点类型
元素节点 | Node.ELEMENT_NODE(1) |
---|
属性节点 | Node.ATTRIBUTE_NODE(2) |
文本节点 | Node.TEXT_NODE(3) |
CDATA节点 | Node.CDATA_SECTION_NODE(4) |
实体引用名称节点 | Node.ENTRY_REFERENCE_NODE(5) |
实体名称节点 | Node.ENTITY_NODE(6) |
处理指令节点 | Node.PROCESSING_INSTRUCTION_NODE(7) |
注释节点 | Node.COMMENT_NODE(8) |
文档节点 | Node.DOCUMENT_NODE(9) |
文档类型节点 | Node.DOCUMENT_TYPE_NODE(10) |
文档片段节点 | Node.DOCUMENT_FRAGMENT_NODE(11) |
DTD声明节点 | Node.NOTATION_NODE(12) |
直接上代码
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>event</title>
</head>
<body><div id="id1" onclick="getdiv(event)">hujiajia</div>
<script>
function getdiv(event){
console.log(event)
console.log(event.toElement.nodeName);
console.log(event.toElement.nodeType);
console.log(event.toElement.nodeValue);
console.log(event.toElement.attributes);
console.log(event.toElement.attributes[0].nodeName);
console.log(event.toElement.attributes[0].nodeType);
console.log(event.toElement.attributes[0].nodeValue);
console.log(event.toElement.attributes[1].nodeName);
console.log(event.toElement.attributes[1].nodeType);
console.log(event.toElement.attributes[1].nodeValue);
console.log(event.toElement.childNodes[1].nodeName);
console.log(event.toElement.childNodes[1].nodeType);
console.log(event.toElement.childNodes[1].nodeValue);
console.log("%cComment:", "color:red")
console.log(event.toElement.childNodes);
console.log(event.toElement.childNodes[0].nodeName);
console.log(event.toElement.childNodes[0].nodeType);
console.log(event.toElement.childNodes[0].nodeValue);
console.log("%cDocument:", "color:#787878")
console.log(event.toElement.ownerDocument.nodeName);
console.log(event.toElement.ownerDocument.nodeType);
console.log(event.toElement.ownerDocument.nodeValue);
console.log("%cDocumentType:", "color:#347ad0")
console.log(event.toElement.ownerDocument.firstChild.nodeName);
console.log(event.toElement.ownerDocument.firstChild.nodeType);
console.log(event.toElement.ownerDocument.firstChild.nodeValue);
}
</script>
</body>
</html>