DOM继承树

本文探讨了DOM继承树的概念,详细阐述了document如何继承自HTMLDocument及其与Document.prototype的关系。同时,解释了如head、body等元素的继承源,并讨论了getElementById、getElementByName、getElementsByTagName等方法的适用范围。另外,提到了HTMLDocument.prototype中定义的常用属性,如body和head,以及Document.prototype上的documentElement属性。最后,概述了getElementsByClassName、querySelector和querySelectorAll等方法在不同原型上的定义。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

一、继承树
在这里插入图片描述

  1. document表示文档对象,而它的构造函数是HTMLDocument

  2. HTMLDocument.prototype.proto = Document.prototype
    因此,document和Document之间的关系就是:
    document继承自HTMLDocument.prototype,而HTMLDocument.prototype又继承自Document.prototype

  3. head,body等标签直接继承自HTMLHeadElement.prototype,HTMLBodyElement.prototype等

  4. getElementById方法定义在Document.prototype上,即Element节点不能调用该方法。

  5. getElementByName方法定义在HTMLDocument.prototype上,即非document元素不能调用该方法。

  6. getElementsByTagName方法定义在Document.prototype和Element.prototype上

  7. HTMLDocument.prototype定义了一些常用的属性,body,head分别指代body,head标签
    document.body = ;
    document.head = ;

  8. Document.prototype上定义了documentElement属性,指代文档的根元素。
    document.documentElement =

  9. getElementsByClassName、querySelector、querySelectorAll在Document.prototype和 Element.prototype上均有定义。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值