0

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.

Community
  • 1
  • 1
薛源少
  • 306
  • 1
  • 6
  • 18

1 Answers1

1

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';
Paul S.
  • 64,864
  • 9
  • 122
  • 138
  • erm, bgColor is depreciated because of non-standard...Thanks, one more knowledge learn... I used `getObjectById ` is because I want to pass the number of rows to the javascript to use it with %2 and change the background color according to it. erm, I dont understand why use elm.style.backgroundColor? Thanks for the knowledge^^ – 薛源少 Sep 02 '13 at 12:07
  • `elm` would be the _Node_ you want. `.style` means the _CSS_ styling of that _Node_ as applied directly to the _Node_. `.backgroundColour` then means the _background-color_ _CSS_ attribute. Setting it is like setting `` – Paul S. Sep 02 '13 at 15:22
  • well, I found [Theme Customizer: IE 8/9 compatibility](http://core.trac.wordpress.org/ticket/20582)... and I try to used the `elm.style.backgroundColor`, the background color do not preview (sometimes) just like the links... – 薛源少 Sep 03 '13 at 02:50