Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IE and document.implementation.createDocument() - which arguments effect correct html nodename case?

Chrome and Firefox like document.implementation.createDocument(). IE9 does not, it demands the namespaceURI and document element name are supplied. This means calling something like document.implementation.createDocument('http://www.w3.org/1999/xhtml','html',null), but this has the bizarre effect of generating an html document that does not use the official HTML element nodeName case. It's supposed to be all-uppercase, and a normal document.createElement("a").nodeName in IE9 will return "A". Using the document.impl... version, [...].createElement("a").nodeName returns "a".

Which magical combination of arguments will effect a document that has correct case rules?

(reason for the question: a million QUnit tests that test DOM fragments expect uppercase nodenames, and will throw errors all over the place with this not-windowed element factory. These tests can all be fixed manually to ignore case, but if there's a way to make IE behave, rather than pretend lowercase element names are okay -they're not, according to the spec- I'll take that before doing manual fixing).

like image 869
Mike 'Pomax' Kamermans Avatar asked Dec 14 '25 15:12

Mike 'Pomax' Kamermans


1 Answers

You will need to use the createHTMLDocument method instead, like this:

document.implementation.createHTMLDocument("").createElement("a").nodeName

(almost in keeping with the DOM4 spec).

createDocument, according to that spec, creates an XML document, which should not coerce the element names to upper case.

like image 161
Alohci Avatar answered Dec 17 '25 07:12

Alohci



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!