最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - document.getElementById('AnyName').innerHTML = content not working in IE or Safari, but working in

programmeradmin3浏览0评论

Busy building a website that after the user has made several selections, graphs are drawn. I am replacing the inner HTML of a div using javascript to go through the different steps, more specifically as shown below:

document.getElementById('AnyName').innerHTML = content;

This is working in Chrome and Firefox but not in Safari or IE.

At the moment content is defined more or less as below, just an example:

var content = (function () {/*
    <div class="selectNavbar">
    Some HTML and other stuff here
    </div>
*/}).toString().match(/[^]*\/\*([^]*)\*\/\}$/)[1];

I have tried replacing innerHTML with with value/textContent as I saw some people were having trouble with Safari and that seemed to fix it, but the page still failed to load in the new HTML.

I have also used the w3 validator but it seems to be only me using sloppy styles, which I don't believe to be the problem here.

Thanks in advance. If anyone needs I can link all the code, but the source can be viewed in above mentioned link .

Busy building a website that after the user has made several selections, graphs are drawn. I am replacing the inner HTML of a div using javascript to go through the different steps, more specifically as shown below:

document.getElementById('AnyName').innerHTML = content;

This is working in Chrome and Firefox but not in Safari or IE.

At the moment content is defined more or less as below, just an example:

var content = (function () {/*
    <div class="selectNavbar">
    Some HTML and other stuff here
    </div>
*/}).toString().match(/[^]*\/\*([^]*)\*\/\}$/)[1];

I have tried replacing innerHTML with with value/textContent as I saw some people were having trouble with Safari and that seemed to fix it, but the page still failed to load in the new HTML.

I have also used the w3 validator but it seems to be only me using sloppy styles, which I don't believe to be the problem here.

Thanks in advance. If anyone needs I can link all the code, but the source can be viewed in above mentioned link .

Share Improve this question edited Apr 17, 2015 at 15:37 Kobus Pitzer asked Apr 17, 2015 at 15:28 Kobus PitzerKobus Pitzer 5741 gold badge4 silver badges13 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 6

I remend you to go through this first innerText vs innerHtml vs label vs text vs textContent vs outerText

I dont know why you went for innerHTML in the first place. I have seen your page's javascript and it seems all you are doing is updating the text value.

innerHTML is used to put/get elements to/from another element
You can use innerText or textContent which will solve your problem textContent will only work on IE11 so it's better go for innerText

or do something like

var divElement=document.getElementById('id');
var value=document.getElementById('someotherid');
if(divElement.textContent)
  divElement.textContent=value;
else 
  divElement.innerText=value;

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论