The best magazine
JavaScript and XHTML
Whether a web page is HTML or XHTML is NOT determined by the doctype tag at the top of the page. As far as web browsers are concerned that reads <!DOCTYPE html> and everything else in the tag is ignored. The only things that actually use anything else that might be found in that tag are validators that you may be using to validate your code. Those validators use the (X)HTML version information in it to determine which set of rules to validate your page content against.
What does determine whether a page is HTML or XHTML is the MIME type. If the MIME type is text/html then the page is HTML and if the MIME type is application/xml+xhtml then the page is XHTML.
These authors assume that the page using an XHTML doctype will be served with a MIME type of text/html. This makes the page HTML and not XHTML. Their referring to the page content as XHTML in this case (which it isn't) instead of referring to it as the HTML that it is has the potential to greatly confuse most beginners as to just what the difference is between HTML and XHTML (and I suspect that many of the authors don't really understand this themselves).
Since the code in the web pages in these books is actually HTML the authors would do better to use a doctype that is less likely to confuse their readers and in fact there is really only one doctype that is appropriate for use in discussing newly created web pages and that is HTML 4 strict. The non-strict variants are intended for use with existing HTML 3.2 web pages that have not yet been fully converted to HTML 4 and therefore shouldn't be used for new pages and as I have already said, using an XHTML doctype on HTML while valid in some situations is just going to confuse readers as to what the difference between HTML and XHTML is.
This doesn't matter as much in a book on (X)HTML as it does in a book on JavaScript since as far as the (X)HTML itself is concerned writing code using XHTML 1.0 and then serving it as HTML is exactly the same as writing HTML 4 except for a few deliberate errors with extra / in the end of some tags which by preceding them with a space you can get the browser to ignore.
In JavaScript though it makes a huge difference whether the page the JavaScript is interacting with is HTML or XHTML. There are two completely different Document Object Models that JavaScript can use depending on whether the web page is HTML or XHTML. Most of the commands that work with one of these DOM will not work with the other DOM which will require a different command to perform the same task. By referring to their page content as XHTML and then teaching the HTML DOM these books completely hide the fact that the XHTML DOM exists and give their reader the impression that the HTML DOM will work with XHTML - which it will not.
The commands that can be used with XHTML are so different in most cases from those that can be used with HTML that for anyone who does know the difference between the two DOMs it is really obvious which of the two that a particular book is using even though the books generally don't even mention the fact that there are in fact two completely different DOMs. When you see a book refer to document.write() or innerHTML or even createElement() or the book contains any reference to Internet Explorer (which as of version 8 still has no support for XHTML) then the DOM being referred to is the HTML DOM.
The XHTML DOM is different because XHTML pages can have multiple namespaces and so the namespace being referenced must be included in most references to the page. The namespace for the regular XHTML is what is defined in the HTML tag where you put <html xmlns="http://www.w3.org/1999/xhtml"> and the page can also contain tags from some other markup language using a different namespace (that's why it has the X for eXtensible on the front). Since the different markup languages used in your page can use the same tag for different purposes the namespace is used to specify which language those tags belong to.
Many references to your XHTML from JavaScript will therefore need to specify which namespace is being referenced and those XHTML DOM commands where a namespace is required will differ from their HTML DOM equivalents by requiring the namespace - for example createElementNS().
The other difference between the HTML and XHTML DOMs is that the XHTML DOM must be accessed using the regular DOM commands. Those shortcut commands that can be used to bypass the regular HTML DOM calls (such as document.write and innerHTML) can not be used at all.
I am not suggesting that these JavaScript books for beginners should teach the XHTML DOM (since all the web pages that beginners will be working with will be HTML). The books though should make it clear that there are in fact two separate Document Object Models and that the one that they are teaching is the HTML DOM. Beginners have enough trouble comprehending what the difference is between HTML and XHTML without these books compounding the problem by referring to their HTML as XHTML.
Over the next few pages we'll look at some of the main differences between JavaScript intended to work with HTML and JavaScript intended to work with XHTML and how is is just about impossible to cater for both at the same time.
Source: ...