Guest citrus_cyanide Posted October 21, 2005 Share Posted October 21, 2005 Please, I need to make this code work just one time so that I can understand it and start making my own similar functions, please tell me what is wrong with this code. <html><head><title>JS Test.</title><script type="text/javascript">function hover(){// Loops through all td tagsvar tds=document.getElementsByTagName('td');for(var i=0;i<tds.length;i++){// If the td tag has class="hover" then it adds mouseover and mouseoutif(tds[i].className=='hover'){tds[i].onmouseover=function(){this.classname="hon"}tds[i].onmouseout=function(){this.classname="hoff"}}}}window.onload=function(){hover()}</script><style>table.hon{background-color:#444444}table.hoff{background-color:#000000}</style></head><body><table bgcolor="#000000"><tr><td class="hover"><font-color="ffffff">HURRY UP AND WORK ALREADY!!!</td></tr></table></html> Like I said, I only need to get this to work once. Just give me a working example and I will be able to figure out how to integrate it how I want. Thanks alot. P.S. I use htis format because I rely heavily on CSS. Link to comment Share on other sites More sharing options...
Chocolate570 Posted October 21, 2005 Share Posted October 21, 2005 window.onload=function(){hover()}First of all, i'm pretty sure it's window.onload="function(){hover()}"And you can put that in the body-onload section. Also, that makes no sense..window.onload=function(){hover()}Just use window.onload="hover()" Link to comment Share on other sites More sharing options...
supatech Posted October 31, 2005 Share Posted October 31, 2005 Yeah, I'd just put the OnLoad function in the body tag, like so: <body onload="hover()"> Try that if you haven't got it sorted already. Link to comment Share on other sites More sharing options...
Jonas Posted October 31, 2005 Share Posted October 31, 2005 <font-color="ffffff"> I can guarantee that code doesn't work properly...Also, you should declare your style type, like this (assuming it's css):<style type="text/css"></style> Link to comment Share on other sites More sharing options...
Guest Gump Posted November 2, 2005 Share Posted November 2, 2005 1.this.classname-----------^should be : this.className2. table.hon ^should be : td.hon alter and try... Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now