<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>节点名称nodeName</title>
<!--
node.nodeName;当node是元素时,获取的node节点名称是(标签)的名称,不带尖括号
node.nodeName;当node是属性时,获取的node节点名称是属性的名称
node.nodeName;当node是文本时,获取的node节点名称是字符串"#text"
-->
</head>
<body>
<p class="p1" style="background: red;">我是p节点的文本子节点</p>
<script>
var p=document.getElementsByTagName("p")[0];//获取p
var text=p.firstChild;//获取p下面的第一个子节点
var attribute=p.getAttribute("class");//获取p的class属性
console.log(p.nodeName);//p的节点名
console.log(text.nodeName);//p下面第一个子节点的名
console.log(attribute.nodeName);//属性节点名
</script>
</body>
</html>