You've deviated from the demo markup. The this keyword refers to the element in which it appears, you have changed which one that is. Where you have this:
Code:
<div class="menutitle"><a href="javascript: void(0);" onclick="SwitchMenu('sub21',this);">Bilstereo/TV</a> (<u>102</u>)</div>
The demo used (without the this keyword):
Code:
<div class="menutitle" onclick="SwitchMenu('sub21',this);">Bilstereo/TV (<u>102</u>)</div>
But to get what I think you are after, you should use:
Code:
<div class="menutitle"><a href="javascript: void(0);" onclick="SwitchMenu('sub21',this.parentNode);">Bilstereo/TV</a> (<u>102</u>)</div>
or:
Code:
<div class="menutitle" onclick="SwitchMenu('sub21',this);"><a href="javascript: void(0);">Bilstereo/TV</a> (<u>102</u>)</div>
And, change your added style to select the desired element:
Code:
.titleon a {
background-color:#000000;
color:#ECECFF;
}
Note: In IE, using href="javascript:void(0);" will cause problems with animated .gif images, sometimes with scripts and possibly with other dynamic content. If you go with:
Code:
<div class="menutitle"><a href="#" onclick="SwitchMenu('sub21',this.parentNode);return false;">Bilstereo/TV</a> (<u>102</u>)</div>
It would be a safer way to do it. So too would be styling and marking up your title division so as to not require the href at all. A good solution here would be to make the above change and then substitute the URL for a page in place of #. This page will be navigated to only by non-javascript enabled browsers and would represent their fall-back content.
Bookmarks