Tuesday, March 18, 2008 #

Changing the background color of a TD

So I just finished spending approximately an hour and a half trying to figure out why my very simple javascript code wasn't working...

function changeColor()
{
     mb.style.backgroundColor = "#000000";
}

Basically, I had an image in the html page, when the mouse went over the image it called that function, which would change the background color of the TD named mb to Black.

I opened up IE and it worked. I opened up Firefox...and nothing happened.

Finally after searching and searching, I found the culprit.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

Can anybody tell me why that's preventing Firefox from changing the background color of a TD?

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <script type="text/javascript">
        function changeImage()
        {
            mb.style.backgroundColor = "#000000";
        }
    </script>
    <title>
    Untitled Page
</title></head>
<body>
        <a href="#"><img border="0" src="sham.jpg" id="sham" onmouseover="changeImage()" /></a>
    <table style="width:100%;">

        <tr>
            <td width="50" height="50" id="mb" bgcolor="#cccccc">
                &nbsp;</td>
        </tr>
    </table>

</body>
</html>

  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

Posted On Tuesday, March 18, 2008 1:45 PM | Feedback (4)