A Reason to Use innerHTML
March 2nd, 2006
Over the last couple of days, I spent hours trying to use DOM techniques to change captions for a Javascript slide-show in a way that respected HTML tags embedded in the text.
Using the DOM to keep the code clean was easy. But it wasn’t easy to find a way that allowed users to include HTML tags in the captions. Javascript DOM nodeValue simply changed everything into HTML entities and the tags displayed uselessly as HTML text. Nothing I did worked.
Finally, I emailed a friend who agreed to tackle the problem. 10 minutes later the solution was in place. What was the solution? innerHTML.
This method is not technically standards compliant, but has huge cross-browser support and was by far the best solution for this problem. Go figure. Playing it safe and using standards compliant techniques isn’t always the best way to approach programming and design, even if it usually is!
Some great discussion has already taken place on this topic at Quirksmode and DomScripting.
Thanks Ryan!
Entry Filed under: Web Design & Scripting






