IE Unable to modify the parent container OR 800a03e8 error

Recently I encountered the following error with IE which left me puzzled and the page unfinished:

Message: HTML Parsing Error: Unable to modify the parent container element 
before the child element is closed (KB927917)
Line: 0
Char: 0
Code: 0

With the Javascript debugger I found a different message:

Could not complete the operation due to error 800a03e8

And what was even more weird was that the page worked fine not only with FF and Chrome but also with IE7 and IE9 and most versions of IE8 too! There were only TWO computers with IE8 in the office where we were able to reproduce the problem.

So after some digging (This took a while because that particular line was a 3rd party Javascript using document.write() so I couldn't modify it NOR wrap it inside a ready handler) I was able to conclude that the line where the debugger caught the error was not the cause of the error.

With that information I was able to trace the problem to another Javascript, which was missing the ready handlers. When I wrapped the code inside $(function() { ... }); the problem was solved.

Lesson learned? Always use the jQuery ready handler, it can save you a lot of trouble!