Sunday, July 25, 2010

Internet Explorer giving a run-time error when executing object.innerHTML

By any chance did you get an “unknown run-time error” while using the following javascript method object.innerHTML=”yourhtml” in Internet Explorer? well I just did and obviously the very helpful (sarcastic) message by Microsoft didn't help at all.

Fortunately the solution is quite simple, for example in this case:

 document.getElementById('cartAddSpecContent').innerHTML = spec;  

All you have to do is to replace the 'cart'AddSpecContent' element (that used to be a

 <p>  

) for a block-level one like

 <div>  

and that's it ;)