Forum Moderators: open

Message Too Old, No Replies

Son of suckerfish javascript question.

         

bazookaman

9:32 pm on Feb 26, 2008 (gmt 0)

10+ Year Member



Is there a way to make this apply to more than one style? In other words, instead of just "mainnav" could I apply it to "bluenav" and "greennav"?

sfHover = function() {
var sfEls = document.getElementById("mainnav").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);

eelixduppy

9:42 pm on Feb 26, 2008 (gmt 0)



If you add everything to the same array then I believe it should work for everything. Try the following:

var main = document.getElementById("mainnav").getElementsByTagName("LI");
var blue = document.getElementById("bluenav").getElementsByTagName("LI");
var green = document.getElementById("greennav").getElementsByTagName("LI");
var sfEls = main.concat(blue, green);

See where that gets you.

bazookaman

9:56 pm on Feb 26, 2008 (gmt 0)

10+ Year Member



ok. I'm guessing I'm still getting an error on the page (in IE6 on the PC) b/c I no longer have the mainnav style in my document? But the javascript is still looking for it?

Please excuse the ignorance, but javascript is NOT my forte. What do i take OUT of the code you posted to just use the bluenav and greenanv? I don't want to screw anything up.

eelixduppy

9:58 pm on Feb 26, 2008 (gmt 0)



Ahh, I'm sorry I thought you meant to include all three. You are going to have to then use the following code:

var blue = document.getElementById("bluenav").getElementsByTagName("LI");
var green = document.getElementById("greennav").getElementsByTagName("LI");
var sfEls = blue.concat(green);

good luck :)

bazookaman

10:02 pm on Feb 26, 2008 (gmt 0)

10+ Year Member



man! that LOOKED like it should have worked!

This is the error I'm getting in IE...

Line: 4
Char: 2
Error: 'document.getElementByld(...)' is null or not an object
Code: 0

Does that mean anything to you?

Thanks so much for the assistance btw.

bazookaman

11:18 am on Feb 28, 2008 (gmt 0)

10+ Year Member



nobody? can someone recommend somewhere else to look for a solution?

mehh

6:08 pm on Feb 28, 2008 (gmt 0)

10+ Year Member



Useualy that means that the script cant find the element is looking for. Did you id your two lists "greennav" and "bluenav"?