Invisible Man wrote:
Thanks for help in advance...
I'm trying to change the background of:
<li class="noflyout " name="leftnav1" ><a href="default.a sp">Home
</a></li>
CSS set it to blue - but want to us JS to change it to red if
the user lands on the page... I've got the following JS:
document.getEle mentsByTagName( "li").eleme nts
["leftnav1"].style.backgrou ndColor= '#cc0000'
getElementsByTa gName() returns a collection of all the elements in the
document with the tag name.
That is likely not the best approach here, it's better to replace NAME
attribute with an ID and use document.getEle mentById():
<li ... id="leftnav1">. ..</li>
...
document.getEle mentById("leftn av1").style.bac kgroundColor='# cc0000';
Read the group FAQ in regard to feature detection and incorporating
support for oder versions of IE with document.all.
<URL:http://www.jibbering.c om/faq/#FAQ4_15>
Your statement should test that objects and methods are supported
before trying to use them and offer alternatives where appropriate:
if (document.getEl ementById ) {
var x = document.getEle mentById("leftn av1");
} else if (document.all ) {
var x = document.all["leftnav1"];
} else {
return
}
if ( x && x.style ) x.style.backgro undColor = '#cc0000';
If you intend using getElementById frequently, you may want to use
something like the DynWrite function mentioned at the above FAQ link.
--
Rob