Irlan agous said:
sorry i forget the function is here:
function switchColors(element, color)
{
links=document.getElementsByTagName("a") ;
for (var i = 0 ; i < links.length ; i ++)
links.item(i).style.color = 'blue' ;
element.style.color=color ;
}
Your function is called switchColors(), you're calling ...
onmouseover="switchColor(this, 'yellow');" ...
You probably want to use -var- to ensure your function variables are
local to the function, and you don't really need item():
function switchColor(element, color)
{
var links = document.getElementsByTagName('a');
for (var ii = 0; ii < links.length; ++ii)
{
links[ii].style.color = 'blue';
}
element.style.color = color;
}
You probably want some appropriate error handling added for browsers
that do no support the methods and properties you are attempting to
access:
function switchColor()
{
return;
}
function switchColorEnabled(element, color)
{
var links = document.getElementsByTagName('a');
for (var ii = 0; ii < links.length; ++ii)
{
links[ii].style.color = 'blue';
}
element.style.color = color;
}
window.onload = function()
{
if (document.getElementsByTagName)
{
var links = document.getElementsByTagName('a');
if (links.length > 0 && links[0].style)
{
switchColor = switchColorEnabled;
}
}
}
I'm still making the assumption that if the first link I retrieve
supports the -style- property, they all will, but I would hope that it's
a fairly safe assumption to make.