Ba loại DOM chính trong lịch sử JS:
- Legacy DOM (DOM Level 0): Sớm nhất. Hỗ trợ tốt mọi browser nhưng chỉ truy cập được forms, images, links. Đã lỗi thời.
- W3C DOM (DOM Level 1+): Chuẩn hóa bởi W3C. Truy cập/sửa đổi toàn bộ nội dung document. Hỗ trợ bởi tất cả browser hiện đại. Tiêu chuẩn hiện tại.
- IE4 DOM: Microsoft giới thiệu trong IE4. IE5+ hỗ trợ W3C DOM cơ bản. Đã lỗi thời.
Ví dụ W3C DOM
<html>
<head>
<title> Document Title </title>
<script>
function myFunc() {
var ret = document.getElementsByTagName("title");
alert("Document Title: " + ret[0].text);
var ret = document.getElementById("heading");
alert(ret.innerHTML);
}
</script>
</head>
<body>
<h1 id="heading">This is main title</h1>
<p>Nhấn để xem kết quả:</p>
<form id="form1" name="FirstForm">
<input type="button" value="Click Me" onclick="myFunc();" />
<input type="button" value="Cancel">
</form>
<form id="form2" name="SecondForm">
<input type="button" value="Don't ClickMe" />
</form>
</body>
</html>