- From: Michael A. Puls II <shadow2531@gmail.com>
- Date: Tue, 06 Oct 2009 10:43:54 -0400
On Tue, 06 Oct 2009 10:14:13 -0400, Hallvord R M Steen <hallvors at gmail.com> wrote: >> You might think so. However, as Michael stated above Opera used to do >> this, and it broke a number of websites that expected >> documentElement.firstChild to be <HEAD> no matter what the actual >> markup looked like. So we had to implement a somewhat magic firstChild >> on documentElement > > ..though less magic than I remembered - it only skips text nodes, not > comments.. And perhaps what happens is that the text node is put > inside body instead? I'd have to do some more testing to tell what > browsers actually do.. Here's an example to play with: document.documentElement.firstChild results: <!DOCTYPE html> <html><!--Not head --><head> <title></title> <script> window.onload = function() { var de = document.documentElement; var fc = de.firstChild; alert(fc); de.insertBefore(document.createTextNode("test"), fc); alert(de.firstChild); }; </script> </head> Safari, Opera, and Firefox with HTML5 parser enabled: alert1: comment node alert2: text node IE8 and Firefox: alert1: head element alert2: text node document.head definitely solves that mess. -- Michael
Received on Tuesday, 6 October 2009 07:43:54 UTC