Forum Moderators: open
<script language="JavaScript">
<!-- Begin
function testThing(theLink) {
if (document.all) {
alert(document.all.theLink.style.color);
}
else{
alert(document.links.theLink.style.color);
}
}
//-->
</script>
Greetings,
Actually, the title of the message is wrong. I'm trying to pass a string, containing the ID of an element (not a property or method), to a script. But the script fails. I've tried calling it as testThing(IDofLink); and testThing('IDofLink');, but either way I get no alert. However, if I hardwire the ID of the link into the script (in place of "theLink"), then I get the alert.
What am I doing wrong?
Thanks!
Perry
fred = document.all[theLink].style.color; Will be fine.
NEVER use eval. Any 'dot' property can be accessed via a string using [] notation.
But, document all is only supported in IE. Use this instead:
fred = document.getElementById(theLink).style.color