This is not a jQuery inquiry. I am utilizing neither an <anchor>
nor a list
for my menu structure. My goal is to have the tab item in the menu appear in a different color when it is active. CSS pseudo-classes such as :active
and :selection
did not yield the desired outcome. The layout of my menu involves using a <label>
within a <p>
tag:
<div id="MainMenu">
<p class="floatLeftP" id="SiteName">Site Name Here</p>
<p class="floatLeftP"><label id="ViewLink1" onclick="mainMenuChg('Home')">HOME</label></p>
<p class="floatLeftP"><label id="ViewLink2" onclick="mainMenuChg('Offered')">OFFERED</label></p>
<p class="floatLeftP"><label id="ViewLink3" onclick="mainMenuChg('Input')">INPUT</label></p>
<p class="floatLeftP"><label id="ViewLink4" onclick="mainMenuChg('Wanted')">WANTED</label></p>
<p class="floatLeftP"><label id="ViewLink5" onclick="mainMenuChg('MyAccount')">My Account</label></p>
<p class="floatLeftP"><label id="ViewLink6" onclick="openHTTPS()">Sign Up!</label></p>
<p class="floatRightP"><label id="ViewLink7" onclick="openHTTPS()">Sign In</label></p>
</div>
The usage of CSS :active
typically applies to links, which are not being utilized in my setup.
Upon clicking most of the menu items, a function named mainMenuChg('argHere')
is executed.
function mainMenuChg(argPage) {
window.location.href = "#" + argPage;
};
This adjustment in the URL triggers an AngularJS router, however, I prefer employing only JavaScript without involving AngularJS. By using the code below, I can alter the color of a menu item:
document.getElementById(theID).style.color = "yellow";
However, the color remains unchanged once set. Clicking on another menu item results in multiple yellow-colored items. The desired functionality is to change the color of the current <label>
while returning the previous one to its original color. Since each menu item has a distinct color, resetting to the default hue is indispensable.
I am seeking a method to retain the value of the old id
without losing it by storing it in a variable. Defining the variable within the function appears to result in loss of its value.
While there are some jQuery solutions available, I specifically require a JavaScript-based approach.