innerHTML Not So Evil After All?
There’s been some discussion about whether using the non-standard innerHTML is an acceptable way to add content. Coming to the defense of the maligned property is this article at Robert Nyman’s site, co-authored by Anne van Kesteren a member of the W3C, stating,
When it comes to having greater scalability in a web page, especially in AJAX scenarios, innerHTML offers unmatched flexibility. There has also been benchmark tests verifying that
innerHTMLis more efficient compared to using DOM methods.
The benchmarks test referred to are here, and show a dramatic speed advantage when choosing innerHTML over DOM methods.
The fact that it is not in a standard is simply because nobody got around to it. If you read the mailing list of the W3C Web API’s Working Group you can see that Opera, Mozilla and Apple want it to be standardized and we bet Microsoft would like the same thing.
As snook pointed out, the XMLHttpRequest object isn’t standard (yet) either. Funny, no one complains about that.
Recognizing that there are some instances where using DOM methods may be more elegant, in many cases, I choose to use innerHTML to update content. It just seems natural, especially when the content is repeatedly generated using the same server-side code.

This website uses IntenseDebate comments, but they are not currently loaded because either your browser doesn't support JavaScript, or they didn't load fast enough.