Jump to content

[SOLVED] Change Table Background Colour Using Javascript


stevesimo

Recommended Posts

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]

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.