Forum Moderators: open

Message Too Old, No Replies

css/js menu bug!

         

webmannw

9:35 am on Nov 26, 2004 (gmt 0)

10+ Year Member



Hi, Sorry if this is a daft or an obscure question. I'm just starting out with Javasctipt!

I ave a css/javascript expanding tree menu that is worlking fine under normal circumstances.

The js is shown below:

if (!document.getElementById)
document.getElementById = function() { return null; }

function initializeMenu(menuId, mainnavId) {
var menu = document.getElementById(menuId);
var mainnav = document.getElementById(mainnavId);

if (menu == null ¦¦ mainnav == null) return;

mainnav.parentNode.style.backgroundImage = "url(../images/plus.gif)";
mainnav.onclick = function() {
var display = menu.style.display;
this.parentNode.style.backgroundImage =
(display == "block")? "url(../images/plus.gif)" : "url(../images/minus.gif)";
menu.style.display = (display == "block")? "none" : "block";

return false;
}
}

And to make sure that the '+' and '-' gifs anr displayes just once per <li> I use the following css line:

background: no-repeat 0em 0.5em;

My problem is that if the user is viewing in a non css enviroment the 'no-repeat' is lost and the whole menu is unusable because the gifs repeat and thus obscure the contents on the menu.

Is there any way of specifying the 'no-repeat' in the javascript?

Thnaks all.

adni18

3:00 pm on Nov 26, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



unfortunately, you need css for this kind of background. Try hooking it up to the guys at CSS [webmasterworld.com].

Bernard Marx

3:08 pm on Nov 26, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Indeed you could specify "no-repeat" in script (element.style.backgroundRepeat='no-repeat', I guess).

But,if the environment is "non-CSS"(whatever that may be) then surely it will have no effect. In this respect, scripting is merely being used to control CSS.
If CSS isn't there...