Question

I currently build a javascript which will change the bgColor of the table row. All is well when I tested it with Google Chrome, but after I try it on IE9 then it just...sometime works, sometimes do not...Do someone here know how can I fixed it? Am I going to throw away the java scripts and build another 1? Below is the related code...

Updated: I manage to change the bgColor using javaScript, but it does not perform correctly until I press F12 or double click the table rows for IE9.

I found out that Website with JS doesn't work in IE9 until the Developer Tools is activated is almost 100% with my situation and there are many more. But, I do not have any code which related to the console or console.log in my program and I had try many methods to find out what is the problem.

But at the end, still back to zero. No idea what is going wrong, need some helps at here... Thanks in advanced

JavaScript

<SCRIPT LANGUAGE="JavaScript">
//......
//......
function setColor(){
if(selectedRow != ""){
      selectedRow.bgColor = originColor;
    }

    var x = getObjectById("row");
    x.bgColor = "#CCCCFF";
    selectedRow = x;
}
</SCRIPT>

HTML

<TD ...  onclick="setColor();"></TD>

Need some hints.

Was it helpful?

Solution

I'm not sure what getObjectById is doing, but you should be setting style.backgroundColor on your HTMLElement rather than the bgColor property. The bgColor property matches with the attribute of the same name, and this attribute has been depreciated since HTML 4.01 and obsolete in HTML5.

elm.style.backgroundColor = '#CCCCFF';
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top