<br><br><div><span class="gmail_quote">2007/1/3, Nick Fitzsimons &lt;<a href="mailto:nick@nickfitz.co.uk">nick@nickfitz.co.uk</a>&gt;:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
On 3 Jan 2007, at 19:05:47, Matt Warden wrote:<br><br>&gt; On 1/3/07, Paul Novitski &lt;<a href="mailto:paul@juniperwebcraft.com">paul@juniperwebcraft.com</a>&gt; wrote:<br>&gt;&gt; At 1/3/2007 06:31 AM, Matt Warden wrote:
<br>&gt;&gt; &gt;I find DOM manipulations to be elegant, once you wrap your ahead<br>&gt;&gt; &gt;around the fact that this is *not* markup anymore, but rather an<br>&gt;&gt; &gt;active document, represented by a tree structure.
<br>&gt;&gt;<br>&gt;&gt; I&#39;ve always considered document.write() to be sloppy, DOM-less<br>&gt;&gt; coding, however the manual does say:<br>&gt;&gt;<br>&gt;&gt; &quot;The text you write is parsed into the document&#39;s structure model. In
<br>&gt;&gt; the example above, the h1 element becomes a node in the document.&quot;<br>&gt;&gt; <a href="http://developer.mozilla.org/en/docs/DOM:document.write">http://developer.mozilla.org/en/docs/DOM:document.write</a>
<br>&gt;<br>&gt; I&#39;m not sure how else it would work. I can&#39;t think through my head how<br>&gt; the markup itself could just be inserted as a text node but somehow<br>&gt; still function as part of the document.<br>
&gt;<br><br>I recently did a number of tests focused on this very issue (in<br>relation to the WaSP&#39;s DSTF&#39;s invitation to assist the IE Team in<br>prioritising DOM fixes for IE.next), and the conclusion I came to was
<br>that the string assigned to the innerHTML property is indeed passed<br>through the HTML parser, at least on IE (and I assume on all<br>browsers). I was able to prove this by triggering certain bugs in<br>IE&#39;s parser when inserting supposedly-valid markup.
<br><br>One interesting side effect of this is that<br><br>someElement.innerHTML = someMarkup;<br>insertedMarkup = someElement.innerHTML;<br>return insertedMarkup == someMarkup;<br><br>doesn&#39;t necessarily return true; indeed, doing a more accurate
<br>comparison by walking the resultant DOM tree, allowing for things<br>like capitalisation of tag names and attributes being unordered, will<br>reveal that the DOM created by the parser won&#39;t necessarily be the<br>same as if the equivalent DOM creation and manipulation methods are
<br>used.<br><br>I&#39;m still getting the results of the tests (which also cover assorted<br>DOM oddities which modify the parser&#39;s behaviour on subsequent<br>insertions of the same markup) written up, and will post a link when
<br>ready, for those who are interested.<br><br>Regards,<br><br>Nick.<br>--<br>Nick Fitzsimons<br><a href="http://www.nickfitz.co.uk/">http://www.nickfitz.co.uk/</a></blockquote><div><br><br>Hello all,<br><br>I&#39;m not a frequent writer on this list,
<br>but I do read a lot of what&#39;s said and this got me interested.<br><br></div>I&#39;m just wondering why there&#39;s ever been a doubt wether or not<br>HTML inserted via either document.write() or .inner/outerHTML<br>
passes through the HTML parser? I thought that was obvious<br>(atleast for .innerHTML) since whatever you assign to it is<br>supposed to be interpreted as HTML, and what else than<br>the browser&#39;s HTML would be used for that?
<br><br>And if it&#39;s parsed as HTML, why not insert it into the DOM tree?<br>Figuring out that it works is easy since whatever (valid) HTML<br>put in there is accessible via the DOM.<br><br>It&#39;s also likely that the dynamically generated DOM would not
<br>be 100% equal to the DOM generated by static HTML since<br>the browser would &quot;consider&quot; different contexts when parsing<br>static vs inserted code. Some browsers also have a thing for<br>&quot;correcting&quot; code by adding/removing/editing tags to fit their
<br>preferred profile, which is why reading back inserted code<br>would not return the original serialization, but a modified version<br>of it.<br><br>Please note that I have no insight whatsoever into the inner<br>workings of browsers, this is simply what I&#39;ve observed
<br>and concluded while developing web-based applications.<br><br>About the use of document.write() and .innerHTML...<br>I prefer to stay away from document.write() for various reasons,<br>but .innerHTML (and also outerHTML) does come in handy every now and then.
<br>Sometimes I might simply use it&#39;s because it&#39;s faster (during runtime)<br>than the equivilent DOM methods, but that&#39;s a whole other discussion.<br>I think .innerHTML will be around for quite a while, and probably 
document.write() too.<br>They are also good when you need to test something fast, but for more things made<br>to be released, DOM is the future.<br><br>Regards,<br><br>Henrik<br></div>