stevesimo Posted January 21, 2008 Share Posted January 21, 2008 Hi, I am trying to change the colour of a table background from white to red using javascript. I have attached an onmouseover event to a link so that when you move over the link the table background colour will change to red. I keep getting a script error message saying that an object is required but not sure what this means. here is my code: <script language="JavaScript"> function changeTableBackground(){ if(document.getElementsByTagName){ var mytable = document.getElementById(theTable); mytable.style.background = '#ff0000'; } } </script> <table width="600" height="400" align="center" border="1" id="theTable"> <tr><td></td></tr> </table> <br> <a href="#" onMouseOver="changeTableBackground()">Change Table Background</a> [code] any help appreciated thanks, steve [/code] Quote Link to comment Share on other sites More sharing options...
rhodesa Posted January 21, 2008 Share Posted January 21, 2008 try changing it to this: var mytable = document.getElementById('theTable'); Quote Link to comment Share on other sites More sharing options...
stevesimo Posted January 21, 2008 Author Share Posted January 21, 2008 It works! Thanks for your help Steve Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.