afish674 Posted January 27, 2012 Share Posted January 27, 2012 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 More sharing options...
justsomeguy Posted January 27, 2012 Share Posted January 27, 2012 The function is document.getElementById, not just getElementById. The function is a method of the document object. Link to comment Share on other sites More sharing options...
afish674 Posted January 27, 2012 Author Share Posted January 27, 2012 Thank you! I can't believe I didn't spot that when comparing to the book. Link to comment Share on other sites More sharing options...
eTianbun Posted January 28, 2012 Share Posted January 28, 2012 I think it ll be much better, if you use CSS for that! Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.