Hi guys,
I have developed a menu structure that has several sub-menus which are hidden until you click on the menu item. Once this happens I have got a onclick event which will display the sub menu below, changes the font colour of the menu item you have just click on and changes the background image of the click menu item. This all works fine in all browsers, however the problem I am having is that when you click on the menu item again I want it to go back to the orignal state. This is working in IE7 and IE8 not tested in IE9 yet, but it is not working in Firefox, chrome, safari, opera and flock. In all the browser it re-hides the sub-menu but does't change the font colour or background image back. I have included the code below
<script type="text/javascript">
<!--
function toggle_visibility(id) {
var e = document.getElementById(id);
if(e.style.display == 'block')
e.style.display = 'none';
else
e.style.display = 'block';
}
function toggle_background(id) {
var e = document.getElementById(id);
if(e.style.background == 'url(img/sb-menu-select-bg.jpg)')
e.style.background = 'url(img/sb-menu-bg.jpg)';
else
e.style.background = 'url(img/sb-menu-select-bg.jpg)';
}
function toggle_linkcolour(id) {
var e = document.getElementById(id);
if(e.style.color == '#bd222f')
e.style.color = '#000000';
else
e.style.color = '#bd222f';
}
//-->
</script>
<div class="menu-layout">
<ul>
<li><a href="">item 1</a></li>
<li id="item2" style="background-image:url(img/sb-menu-bg.jpg);"><a id="item2-link" href="#" style="color:#000000;" onclick="toggle_visibility('sub-item2'); toggle_background('item2'); toggle_linkcolour('item2-link');">item 2</a>
<ul style="display:none;" id="sub-item2">
<li><a href="">sub item 1</a></li>
<li><a href="">sub item 2</a></li>
<li><a href="">sub item 3</a></li>
<li><a href="">sub item 4</a></li>
</ul>
</li>
<li><a href="">item 3</a></li>
<li><a href="">item 4</a></li>
</ul>
</div>
if anyone can see what is causing this it be very much appreciated
thanks in advance
shuka