It is that wonderful time of year again. Head over to 24ways.org for you daily dose of web design and development articles and tutorials.
Archive for the ‘DOM’ Category
24 ways - web design and development articles and tutorials for advent
Tuesday, December 1st, 2009innerHTML on P fails
Wednesday, July 22nd, 2009From http://channel9.msdn.com/Wiki/InternetExplorerProgrammingBugs/
innerHTML on P fails
Using innerHTML to insert new content into a p tag seems to fail consistently in 6.0.2900.2180.xpsp.050301-1521 on XP SP2. I have a repro case located at http://www.blowery.org/test/innerhtmlandp.html for your enjoyment. Just click on the link and you’ll see IE bomb out. I’ve also seen it silently fail, but I’m yet to come up with a repro case for that.
If you use a div instead of a p, innerHTML works as expected.
This behavior is by design
according to http://msdn.microsoft.com/workshop/author/dyncontent/content.asp
“Can’t put invalid HTML in the document: You cannot assign a string to innerHTML or outerHTML that contains invalid HTML. For example, trying to replace the content of the p element with another p will fail. A p element can only contain text and inline elements. However, replacing the entire p element with another p would work just fine.”
In your repro case you insert
into exististing
. Unfortunately similar mistakes break AJAX updaters on IE. — woid