节点名称nodeName

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>节点名称nodeNametitle>
    
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>

你可能感兴趣的:(节点名称nodeName)