Thuộc tính nodeType nút phần tử trong JavaScript

Trình soạn thảo - Thuộc tính nodeType nút phần tử trong JavaScript

Kết quả - Thuộc tính nodeType nút phần tử trong JavaScript

Tự code rồi chạy thử... Chạy Thử
<!DOCTYPE html>
<html>
<head>
<title>Thuộc tính nodeType nút phần tử trong JavaScript</title>
</head>
<body>

<h1>Thuộc tính nodeType nút phần tử trong JavaScript</h1>
<p>Dùng để phân loại node (nút), giá trị phân loại của nodeType nằm trong khoảng từ 1 tới 12, nút phần tử tự tạo bằng document.createElement() hay nút phần tử sau khi document.getElementById() một phần tử HTML sẽ có nodeType bằng 1:</p>

<div id="divid" >Nút phần tử của phần tử HTML DIV có nodeType: <span ida="ketquadiv"></span></div>
<p id="pid" >Nút phần tử của phần tử HTML P có nodeType: <span id="ketquap"></span></p>
<p >Kết quả nút phần tử ul tự tạo: <span id="nutkq"></span></p>
<script>
// nutdiv là nút phần tử sau khi lấy phần tử html divid
const nutdiv = document.getElementById("divid");
// Nhúng nodeType
document.getElementById("ketquadiv").innerHTML = nutdiv.nodeType;
// nutp là nút phần tử sau khi lấy phần tử html pid
const nutp = document.getElementById("pid");
// Nhúng nodeType
document.getElementById("ketquap").innerHTML = nutp.nodeType;
// Tạo nút phần tử ul
const nutul = document.createElement("ul");
// Nhúng nodeType
document.getElementById("nutkq").innerHTML = nutul.nodeType;
</script>
</body>
</html>