Hallo,
@Jobo:
Soweit ich weiß gehört innerHTML leider nicht zum Standard oder täusche ich mich da?
Crockford (aus einem ppt-Dokument):
innerHTML
* The W3C standard does not provide access to the HTML parser.
* All A browsers implement Microsoft's innerHTML property.
Which Way Is Better?
* It is better to build or clone elements and append them to the document?
* Or is it better to compile an HTML text and use innerHTML to realize it?
* Favor clean code and easy maintenance.
* Favor performance only in extreme cases.
und
"The W3C committee that was putting all this together, it never occurred to them that people would want to process their own HTML text within a script within a browser. ...
Microsoft recognized that that was terrible, so they came up with something called innerHTML, which is a bad name for what it does. I think it's a bad API. ... , but still, it works.
It turns out that something browsers are really good at is parsing HTML and building trees, so this can be a very effective way of doing things. Unfortunately, it's a security hazard if you have any user-generated text that's getting put into the structure ... So you need to be really careful in generating text to go to innerHTML.
All of the other browser makers recognize that Microsoft was right in this and that the W3C model was deficient, so all of the browsers implement innerHTML even though no standard requires it. It raises a question for the developer: which one should you use? If you're making new content to put into a page, should you build each of the nodes individually and paste them all together and plug them in, or should you build up a big text and use innerHTML to do that?
My advice is, do the one that favors clean code and easy maintenance for your application. This is, in most cases, something that should not be decided in terms of performance. Performance should only influence you in extreme cases. In ordinary cases, if performance is not going to be undermining the user experience, choose the one that makes the most sense. If performance is an issue then you want to use innerHTML, because browsers are really good at that. Even though it appears that the browser's doing a lot more work, it goes a lot faster. I'll tell you why in a little bit."
aus http://developer.yahoo.com/yui/theater/video.php?v=crockonjs-4
Gruß
jobo