Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is the DOCTYPE relevant only to the markup or also to the DOM?

Up to what level of abstraction does the <!DOCTYPE> declaration (and content-type) of a document remain relevant?

For example, if I'm working with XHTML but want to use an element which is not available in XHTML - an easy example being an iframe - would it be bad practice to programatically add the element with JavaScript? Or do I either have to not use the iframe or not use XHTML?

A validator will still validate the document - since it doesn't execute the JS - but is there something theoretically wrong with modifying the DOM so it is no longer consistent with the <!DOCTYPE> (and returned content-type), or is the <!DOCTYPE> only relevant to the markup when it is in textual form?

Addendum

To be more specific, my question isn't about how the <!DOCTYPE> will affect JavaScript or how JavaScript will execute, but how it should affect a developers choices with respect to adding and removing and modifying elements programatically.

My example is if a client both wants XHTML compliance and WYSIWYG editors, what do you do with the iframe which often comes with WYSIWYG editors? Should you remove it from the markup, only to document.appendChild() it in the JS? Or do you tell your client they have to choose between the two - iframe or XHTML?

like image 853
Richard JP Le Guen Avatar asked Jan 25 '10 16:01

Richard JP Le Guen


1 Answers

The DOCTYPE definition, in standards terms, describes the markup. Thus once the markup has been parsed by a user agent, the DOCTYPE is irrelevent in that respect. In practical terms, the DOCTYPE also triggers browser behaviors, so what you do with/to the DOM dynamically is in that way affected by the DOCTYPE.

like image 53
Pointy Avatar answered Oct 13 '22 10:10

Pointy