admin管理员组文章数量:1322838
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.
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.
4 Answers
Reset to default 8IE 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.
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.
Just use jQuery and forget about all the horrible cross browser problems - you won't go back!
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.
本文标签: javascriptWhy does html work and not innerHTML or appendChildStack Overflow
版权声明:本文标题:javascript - Why does .html work and not innerHTML or appendChild - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742116261a2421480.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论