niche Posted December 8, 2011 Share Posted December 8, 2011 This is a bout a script I'm using to learn more about javascript. I think this is the offending line that won't display in IE9. div.setAttribute("style","background-color:red;"); Does IE have a problem with setAttribute(), or is it something else? Here's what I think is the relevant part of my code: if (xmlhttp.readyState==4 && xmlhttp.status==200) { var div = document.createElement('div'); div.setAttribute('id', 'link_container'); div.setAttribute("style","background-color:red;"); div.style.width = '300px'; div.style.height = '100px'; div.style.margin = '-15px 0px 0px 75px'; var txt=xmlhttp.responseText; var strA = txt.slice(0,txt.indexOf(",")); //define number of cycles of For Loop var str = txt.substr(txt.indexOf(",")+1); //cut 1st position from string and save remaining info for (i=0; i<=strA; i++){ var newLink = document.createElement('a'); //create anchor var linkName = str.slice(0,str.indexOf(" ,")+1); var linkName = linkName.split(' ').join(''); newLink.href = "http://localhost/" + linkName+".php"; newLink.innerHTML = linkName; var str = str.substr(str.indexOf(",")+1); div.appendChild(newLink); var newBr = document.createElement('br'); //create break iv.appendChild(newBr); } document.getElementsByTagName('body')[0].appendChild(div); Link to comment Share on other sites More sharing options...
Ingolme Posted December 8, 2011 Share Posted December 8, 2011 Rather than setting the value of the attribute, try actually changing the style: div.style.backgroundColor = "red"; Link to comment Share on other sites More sharing options...
thescientist Posted December 8, 2011 Share Posted December 8, 2011 Not to dismiss Ingolme's valid suggestion, but does the IE error console give you any feedback? Link to comment Share on other sites More sharing options...
Ingolme Posted December 8, 2011 Share Posted December 8, 2011 I haven't tested to make sure, but I think that in Internet Explorer the setAttribute() function doesn't do anything but change the text content of the attribute without actually updating properties of the HTML DOM. If that is the case, Internet Explorer won't show any errors even if it's not doing anything. Link to comment Share on other sites More sharing options...
niche Posted December 8, 2011 Author Share Posted December 8, 2011 That worked Ingolme. thescientist asked about error console and there was one. I didn't think to check it> it was: SCRIPT5007: Unable to set value of the property 'innerHTML': object is null or undefined. Thanks for asking and thanks also to thescientist. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.