Jump to content

Dynamic background change on DIV


Recommended Posts

Hi all, I am trying to write a simple script to change the background colour of a div when a user hovers their mouse over the div, and then change it back when they move away. My code is as follows:

var contentBox=getElementById("mainContent");var footerDiv=getElementById("footer");contentBox.onmouseover= function(){contentBox.style.backgroundColor="#fff";};contentBox.onmouseout= function(){contentBox.style.backgroundColor="#09C";};

I get an error in firefox saying that "getElementById is not defined" but it is? I don't understand. I've checked this against the code in the book i'm using and its the same (apart from my div names being different.) Could someone please point out what is wrong? Many thanks, Anthony

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Create New...