3

I am trying to add an ajax response to a div (it's HTML code with tables, forms, etc).

In FF innerHTML works perfectly, but in IE it gives me an unknown error.

I tried lots of stuff, but I only got it working when I added jQuery and ran the .html method on the div I want the code inserted into.

Anyone care to explain why this works and not a simple innerHTML? I tried looking at the .html() code, but I guess I am not the great at JS because I didn't understand what it was doing.

Mark Amery
  • 143,130
  • 81
  • 406
  • 459
AntonioCS
  • 8,335
  • 18
  • 63
  • 92

4 Answers4

9

IE has several documented (pre | table (thead, tbody, tr, tfoot) | div | select) .innerHTML bugs.

Thus libraries like jQuery abstract away those bugs for you by applying workarounds where needed for IE.

As for your specific error... without seeing the code it is hard to tell.

Setting the .innerHTML on pre's, certain div's, select's (if it does fail, will fail silently) but setting the .innerHTML on certain table elements (in certain versions of IE) will actually throw an error/exception.

Note: The issue with setting the .innerHTML of a div is very specific in condition and only occurs in IE6 & IE7.

Michael Kohne
  • 11,888
  • 3
  • 47
  • 79
scunliffe
  • 62,582
  • 25
  • 126
  • 161
0

IE is fussy about changing <table>s from javascript. I've run into trouble before if I don't specify the table down to the last detail, including the <tbody> tag.

Jonathon Faust
  • 12,396
  • 4
  • 50
  • 63
-1

Just use jQuery and forget about all the horrible cross browser problems - you won't go back!

Nick Craig-Wood
  • 52,955
  • 12
  • 126
  • 132
-2

I have same problem every day. Try with .innerText instad of .innerHTML, that will solve your problem. Answer is Javascript is parsed different in IE and FF.

Siblja
  • 859
  • 2
  • 12
  • 19
  • 1
    Setting the .innerText won't work if the content truly is HTML. @AntonioCS is already using jQuery thus has solved the issue - he's just not sure exactly why IE is failing. – scunliffe Dec 04 '09 at 19:38