YouTip LogoYouTip

Prop Documenttype Name

## XML DOM DocumentType.name Property The `name` property of the `DocumentType` object returns the name of the Document Type Definition (DTD). This is the identifier that immediately follows the ` ]> Tove Jani Reminder Don't forget me this weekend! ``` The following JavaScript code loads `note_internal_dtd.xml` and retrieves the name of its DTD: ```javascript // Load the XML document const xmlDoc = loadXMLDoc("note_internal_dtd.xml"); // Retrieve and display the DTD name const doctypeName = xmlDoc.doctype.name; console.log(doctypeName); // Output: "note" ``` ### Example 2: Checking the Doctype in an HTML5 Document You can also use this property in modern web browsers to inspect the doctype of the current HTML page: ```javascript // For a standard HTML5 document: console.log(document.doctype.name); // Output: "html" ``` --- ## Considerations & Browser Compatibility 1. **Read-Only:** The `name` property is read-only. You cannot modify the doctype name programmatically using this property. 2. **Null Value:** If the XML or HTML document does not have a `` declaration, `document.doctype` will return `null`. Attempting to access `.name` on a null object will throw a `TypeError`. Always perform a null check in production code: ```javascript if (document.doctype) { console.log("Doctype name:", document.doctype.name); } else { console.log("No DOCTYPE declared for this document."); } ``` 3. **Browser Support:** This property is widely supported across all modern browsers (Chrome, Firefox, Safari, Edge) and legacy browsers (including Internet Explorer 9+).
← Prop Documenttype SystemidProp Documenttype Internalsubs β†’