DocumentType: name 属性

Baseline 已广泛支持

此特性已相当成熟,可在许多设备和浏览器版本上使用。自 ⁨2015 年 7 月⁩以来,各浏览器均已提供此特性。

DocumentType 的只读属性 name 返回文档的类型。

对于人工(synthetic)创建的 DocumentType,此属性反映在 DOMImplementation.createDocumentType() 中作为参数传入的值。

对于 HTML 文档,无论源代码中的实际 doctype 是什么,浏览器都会将其设置为 html

字符串。

示例

js
const docType = document.implementation.createDocumentType("html", "", "");

console.log(docType.name); // Displays `html`

规范

规范
DOM
# dom-documenttype-name

浏览器兼容性