I am passing a string containing HTML tags (center, ul, etc) to a function which then places it in a div, span or p innerHTML. This works great in all browsers but IE, which displays nothing. I tracked the pro开发者_如何学Goblem the the tags, because plain text does display in IE.
I am using IE 9. The code is a little long for posting, but here is the idea:
str='<center>Some text</center>';
displayText('divId',str);
function displayText(id,str)
{ document.getElementById(id).innerHTML=str; }
Sorry everyone. I found that I could not set the innerHTML of a [P] element. I changed it to a [span] and it worked.
innerHTML
is not a good idea (or needs a workaround) for <table>
, <select>
, <p>
elements. This is a known limitation in older versions IE.
Also see this question IE innerHTML error.
Glad that you found a solution..
You should consider using jquery. Then you don't have to worry about all the cross browser implementations & instead focus on adding/enhancing functionality & user experience on your site/application.
精彩评论