Forum Moderators: open
<script type="text/javascript"><!--//--><![CDATA[//><!--sfHover = function() {
var sfEls = document.getElementById("nav").getElementsByTagName("LI");
for (var i=0; i<sfEls.length; i++) {
sfEls[i].onmouseover=function() {
this.className+=" sfhover";
}
sfEls[i].onmouseout=function() {
this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
}
}
}
if (window.attachEvent) window.attachEvent("onload", sfHover);
//--><!]]></script>
any help and advice will be apreciated
if (window.attachEvent) window.attachEvent("onload", sfHover);
/*? */
else window.addEventListener('load',sfHover,false);
/*
Defined function as named function.
- Assignment statement needn't then
come after definition.
*/
function sfHover()
{
/* Assumed: target class of UL is 'sf' */
var regSfUL = /\bsf\b/;
var ULs, UL, LIs, LI, i=j= -1;
ULs = document.getElementsByTagName("ul");/* Loop stops when ULs[n]--> null */
while( UL=ULs[++i] )
{
/* Tested className with RE
- so multiple classNames are handled
RE predefined for extra a fish in sea
*/
if( regSfUL.test(UL.className) )
{
j = -1;
LIs=UL.getElementsByTagName("li");
while( LI=LIs[++j] )
{
LI.onmouseover = over;
LI.onmouseout = out;
}
}
}/* Defined event handler functions outside the loop
- more efficient (speed & memory).
Kept as inner functions to preserve global namespace
- OK, since outer function is only called once.
If you are paranoid about memory leaks you could
define these externally.
*/
function out()
{
this.className=this.className.replace(/ sfhover\b/, "");
}function over()
{
this.className+=" sfhover";
}}