<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">
    <channel>
        <title>DOM Scripting comments: The innerHTML dilemma</title>
        <link>http://domscripting.com/blog/display/35</link>
        <description>The new version of Firefox supports innerHTML, even in correctly served XHTML documents.</description>
        <language>en</language>
        <item>
            <title>Adam Messinger</title>
            <link>http://domscripting.com/blog/display.php/35#comment158</link>
            <content:encoded><![CDATA[<p>Well said, Jeffrey. I made a similar point in my own post referencing this one. As with most things, compromise and moderation are the best answer.</p>
]]></content:encoded>
            <pubDate>Tue, 20 Dec 2005 20:12:45 GMT</pubDate>
        </item>
        <item>
            <title>Jeffrey Schrab</title>
            <link>http://domscripting.com/blog/display.php/35#comment157</link>
            <content:encoded><![CDATA[<p>I had a chance to attend Adaptive Path&#8217;s &quot;Designing and Building with Ajax&quot; seminar and this subject came up (I was the one that brought it up).  The Ajaxian.com guys were there - I can say they appear to be VERY experienced on the subject.  And here&#8217;s what they had to say on the matter:</p>

<p>1) innerHTML is faster than DOM &quot;createElement&quot; methods.  Really.  Potentially Wicked Fast(tm) in comparison.</p>

<p>2) Use of innerHTML is recommended if your need is one way.  That is, you are just presenting content, after which you are &quot;done.&quot;  However, if you need to refer/traverse a DOM branch that you are changing, then you should use &quot;createElement&quot; DOM methods.</p>

<p>In summary, which to use?  Answer: both.  It depends on your case.</p>
]]></content:encoded>
            <pubDate>Tue, 20 Dec 2005 19:36:32 GMT</pubDate>
        </item>
        <item>
            <title>Adam Messinger</title>
            <link>http://domscripting.com/blog/display.php/35#comment153</link>
            <content:encoded><![CDATA[<p>Jonathan Snook said:
&quot;I think innerHTML is sexy. It’s so easy as to be sleazy.&quot;</p>

<p>Oh, great. Now innerHTML will be forever personified in my mind as a smirking, raven-haired seductress in a dress cut down to here and slit up to there, throwing herself at me despite my best efforts to walk the straight and narrow of semantically correct code.</p>

<p>Maybe I just need to get out more.</p>
]]></content:encoded>
            <pubDate>Sun, 18 Dec 2005 07:41:59 GMT</pubDate>
        </item>
        <item>
            <title>vin</title>
            <link>http://domscripting.com/blog/display.php/35#comment152</link>
            <content:encoded><![CDATA[<p>Risking a little bit of deviation I would appreciate some advice from you guys.
I have this slow real slow piece of code involving innerHtml. Now we are thinking of changing it to DOM just to speed up things.
The table generated is small average 6 rows and 4 columns.
Do you think DOM will speed it up? 
I dont see how!The looping and all will remain the same.</p>
]]></content:encoded>
            <pubDate>Thu, 15 Dec 2005 18:41:08 GMT</pubDate>
        </item>
        <item>
            <title>Brooks</title>
            <link>http://domscripting.com/blog/display.php/35#comment151</link>
            <content:encoded><![CDATA[<p>I&#8217;m with Isofarro. I have a PHP script that connects to MySQL and returns me a formatted HTML table. I then load that into a page without having to refresh via xmlhttprequest. It works great except for in Explorer which does not allow writing innerHTML to a table.</p>

<p>I am a beginner and innerHTML is a good way for me to get results without having to deal with 20 lines of DOM work that twists my brain to pieces.</p>

<p>If anyone knows a way to simply get MySQL data into a page and resort/ re-query without refreshing the page without using innerHTML, drop me a line!</p>
]]></content:encoded>
            <pubDate>Tue, 13 Dec 2005 06:47:37 GMT</pubDate>
        </item>
        <item>
            <title>Dustin Diaz</title>
            <link>http://domscripting.com/blog/display.php/35#comment149</link>
            <content:encoded><![CDATA[<p>Savvy meetin&#8217; you up here Jeremy. We should get some lawn chairs for our little fence. I&#8217;ll bring along some fishing poles.</p>

<p>@Shaun: Nah. More talk, less development. It gives us something to ponder.</p>
]]></content:encoded>
            <pubDate>Wed, 07 Dec 2005 05:02:28 GMT</pubDate>
        </item>
        <item>
            <title>Shaun Inman</title>
            <link>http://domscripting.com/blog/display.php/35#comment148</link>
            <content:encoded><![CDATA[<p>Someone should just write a library that takes a string of (X)HTML, parses it for tag structure and then adds it to a given element using the &quot;standard&quot; methods. Everyone&#8217;s happy! ;)</p>
]]></content:encoded>
            <pubDate>Mon, 05 Dec 2005 15:55:22 GMT</pubDate>
        </item>
        <item>
            <title>Jeremy Keith</title>
            <link>http://domscripting.com/blog/display.php/35#comment147</link>
            <content:encoded><![CDATA[<p>Well, clearly this an issue that is loaded with strong feelings from both sides. I find it somehow reassuring that people can be so passionate about it, whether they&#8217;re for or against innerHTML.</p>

<p>Me? I&#8217;m quite comfy up here on my fence, thank you very much.</p>
]]></content:encoded>
            <pubDate>Mon, 05 Dec 2005 13:51:00 GMT</pubDate>
        </item>
        <item>
            <title>minghong</title>
            <link>http://domscripting.com/blog/display.php/35#comment146</link>
            <content:encoded><![CDATA[<p>innerHTML is ugly. Don&#8217;t use it. Imagine XHTML with multiple namespace, I think innerHTML will fail to have consistent cross-browser output.</p>
]]></content:encoded>
            <pubDate>Sun, 04 Dec 2005 05:59:03 GMT</pubDate>
        </item>
        <item>
            <title>Aaron Gustafson</title>
            <link>http://domscripting.com/blog/display.php/35#comment145</link>
            <content:encoded><![CDATA[<p>Ooh, I want a pony&#8230; no, on second thought, I want a llama. Or an alpaca.</p>

<p>As for innerHTML&#8230; I always feel dirty when I use it, so I don&#8217;t use it often. I&#8217;m a casual user. Just when I&#8217;m by myself and know it&#8217;s not hurting anyone but me.</p>
]]></content:encoded>
            <pubDate>Sat, 03 Dec 2005 22:23:37 GMT</pubDate>
        </item>
        <item>
            <title>David Glasser</title>
            <link>http://domscripting.com/blog/display.php/35#comment144</link>
            <content:encoded><![CDATA[<p>I think what would be nice would be if JavaScript had syntactic sugar that let you type (valid!) XML, possibly with some sort of substitution mechanism, and have it turn out as the DOM object.</p>

<p>I’d also like a pony.</p>
]]></content:encoded>
            <pubDate>Fri, 02 Dec 2005 21:43:04 GMT</pubDate>
        </item>
        <item>
            <title>Patrick</title>
            <link>http://domscripting.com/blog/display.php/35#comment143</link>
            <content:encoded><![CDATA[<p>I&#8217;ve been struggling with this same issue for a while now.  And (I surprised myelf here) I came out in favor of innerHTML.  I may have a differernt perspective though.  I work primarily on LARGE applications, where maintainability is priority #1.  </p>

<p>So if I&#8217;m populating a page with data via ajax, which is easier to maintain? 
1. A page that delivers XML, followed by many (many) lines of javascript removing DOM elements, creating DOM elements, appending elements etc. Or,
2. A page that delivers HTML, followed by one line of javascript that inserts it in the page.</p>

<p>Option 2 is infinitely easier to maintain (especially across developers).  I&#8217;ve thought about this and written about it (<a href="http://www.agavegroup.com/?p=43">http://www.agavegroup.com/?p=43</a>) and just can&#8217;t get away from the simplicity of innerHTML (and the fact that it works 100% of the time&#8230;)</p>
]]></content:encoded>
            <pubDate>Fri, 02 Dec 2005 21:00:48 GMT</pubDate>
        </item>
        <item>
            <title>Isofarro</title>
            <link>http://domscripting.com/blog/display.php/35#comment142</link>
            <content:encoded><![CDATA[<p>Using DOM methods instead of innerHTML is obviously the more correct course of action. But that&#8217;s only useful if the data you are inserting is in an object format already. What happens when you receive HTML markup as a text string - how does one convert that to a DOM object and insert it?</p>

<p>A typical example is inserting an entry from an RSS feed into an HTML page. The vast majority of feeds use CDATA or entity escaped markup for the content - that&#8217;s just a text string on HTML markup. What can be done other than innerHTML it right into the current node?</p>

<p>I&#8217;m toying with the idea of pushing the markup through a DOM Parser and get an HTML tree - but its not as well documented as XmlHttpRequest.</p>

<p>But then what happens if the stringified markup is invalid?</p>

<p>This is a trade off between the purity of unobtrusive javascript, and the spirit of DOM updates, and the practical problems out there on the web.</p>

<p>Unfortunately, most of the HTML out there is basically a text string. But then Internet Explorer has been dealing with that problem for years.</p>
]]></content:encoded>
            <pubDate>Fri, 02 Dec 2005 14:04:03 GMT</pubDate>
        </item>
        <item>
            <title>l.m.orchard</title>
            <link>http://domscripting.com/blog/display.php/35#comment141</link>
            <content:encoded><![CDATA[<p>On the other hand&#8230;  MochiKit has a pretty nice functional system of shortcuts for generating DOM structures to replace those 20 lines of createElement() / appendChild() calls.</p>

<p><a href="http://www.mochikit.com/doc/html/MochiKit/DOM.html#creating-dom-element-trees">http://www.mochikit.com/doc/html/MochiKit/DOM.html#creating-dom-element-trees</a></p>
]]></content:encoded>
            <pubDate>Fri, 02 Dec 2005 07:33:31 GMT</pubDate>
        </item>
        <item>
            <title>nortypig</title>
            <link>http://domscripting.com/blog/display.php/35#comment140</link>
            <content:encoded><![CDATA[<p>Well written Jeremy and I&#8217;m not sure which side I&#8217;d drop on that one either. I think its about making educated decisions on these grey areas on a case by case basis.</p>
]]></content:encoded>
            <pubDate>Thu, 01 Dec 2005 22:13:41 GMT</pubDate>
        </item>
        <item>
            <title>Dustin Diaz</title>
            <link>http://domscripting.com/blog/display.php/35#comment139</link>
            <content:encoded><![CDATA[<p>Jeremy, I think I too am on the fence with innerHTML. It works and I don’t think it’s bad programming practice. It’s way too widely supported, and browsers are even going forward with it (like you mentioned 1.5 giving innerHTML xml support (shouldn’t it be called innerXML)).</p>
]]></content:encoded>
            <pubDate>Thu, 01 Dec 2005 21:44:07 GMT</pubDate>
        </item>
        <item>
            <title>André Luís</title>
            <link>http://domscripting.com/blog/display.php/35#comment138</link>
            <content:encoded><![CDATA[<p>There there… it’s ok. We forgive you, Jeremy… :P</p>

<p>I’m with Jonathan. If it’s widely supported, has proven to be faster (<a href="http://www.quirksmode.org/dom/innerhtml.html">http://www.quirksmode.org/dom/innerhtml.html</a>), why should we not use it? </p>

<p>It’s funny how discussion about innerHTML is starting around the web at the moment, and i bet it’s due to the AHAH microformat. Someone asked me about the browser support of this property when i posted a link to AHAH. Funny. :)</p>
]]></content:encoded>
            <pubDate>Thu, 01 Dec 2005 19:43:54 GMT</pubDate>
        </item>
        <item>
            <title>Jonathan Snook</title>
            <link>http://domscripting.com/blog/display.php/35#comment137</link>
            <content:encoded><![CDATA[<p>I think innerHTML is sexy. It’s so easy as to be sleazy. </p>

<p>Just because the DOM2 methods are more structured doesn’t mean that there isn’t room for a quicker and easier approach to content/element insertion. I hear the same argument about HTML vs XHTML. &#8220;Because people can screw up HTML, we should force everybody to use XHTML.&#8221; Next you’ll hear people say that JavaScript shouldn’t be used because it’s dynamically typed.</p>

<p>I don’t know about you guys but I’d rather save myself the time of having to code 20 lines of createElement/appendChild’s when a single innerHTML will suffice.</p>
]]></content:encoded>
            <pubDate>Thu, 01 Dec 2005 16:47:21 GMT</pubDate>
        </item>
        <item>
            <title>Martin Tomes</title>
            <link>http://domscripting.com/blog/display.php/35#comment136</link>
            <content:encoded><![CDATA[<p>I do not believe you should ever use innerHTML, no matter how convenient or tempting.  I have done most of my XML work in the non-web world writing web applications in Delphi.  It is very tempting to put together an XML fragment using string function and add to an XML document.  But I have been bitten badly by doing this.  The XML parser properly understands the XML document character set and the escaping rules, it is very easy to end up with bad data in the XML.</p>

<p>Just do not go there, write some JavaScript helper functions and do it the right way.</p>
]]></content:encoded>
            <pubDate>Thu, 01 Dec 2005 13:57:05 GMT</pubDate>
        </item>
        <item>
            <title>Lachlan Hunt</title>
            <link>http://domscripting.com/blog/display.php/35#comment135</link>
            <content:encoded><![CDATA[<p>I have never and will never use innerHTML for anything other than testing.  It’s so unstructured, it feels like bad programming practice and is on the same level as document.write() (which will never work in XHTML and I will also never use in HTML).</p>

<p>I’m fairly disappointed with Firefox for adding support for it.  People should just learn to use the much more structured DOM2 methods.  However, it is good that Firefox’s implementation for XML documents will fail if it’s not well formed, unlike Opera.</p>
]]></content:encoded>
            <pubDate>Thu, 01 Dec 2005 04:47:56 GMT</pubDate>
        </item>
   </channel>
</rss>