...

View Full Version : functions don't work, need help changing things



cookiecaper
06-01-2005, 04:59 AM
Hi everyone. I've written a small function to change the background color of an anchor. It changes when somebody clicks on it from a list of FAQs.

I added a line to try to change back to white when somebody clicks on another one so that only the one most recently clicked on is highlighted.

Also, anytime I try to put something in a function, it stops working. Any ideas?


var aneo;
function setbg(aneo)
{
document.getElementByTagName("A").style.backgroundColor='white';
document.getElementById("aneo").style.backgroundColor='yellow';
return 0;
}


<a href="#cash" onClick="javascript:setbg('cash');">...</a>

Any suggestions? Thanks!

Astro-Boy
06-01-2005, 06:15 AM
getElementsByTagName() returns an array of all the tags on your page. So you would need to do something like this instead;


var links = document.getElementsByTagName("A");
for (i=0; i<links.length; i++) {
links[i].style.backgroundColor = "white";
}



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum