JK Web Studio

Specializing in efficient and user friendly web design solutions

info@jkwebstudio.com

innerHTML on P fails

From 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

Leave a Reply