I am trying to add a class .up to some menu items when another item is clicked. I am using js to add the class when the link is not opened in a new tab or window i.e. when item-129 is clicked the class up should be added to items 126, 127 and 128 however it is not working. Below are the js and html codes that I am using.
js code
keypressed = null;
$(window).keydown(function(event) {
keypressed = event.keyCode;
});
$(window).keyup(function(event) {
keypressed = null;
});
$("#item-129").click(function(event) {
// Don't animate if command keys or ctrl keys held down
if (keypressed == 91 || keypressed == 92 || keypressed == 17) {
return true;
}
event.preventDefault();
$("#item-126, #item-127, item-128").addClass("up");
}, function() {
$(this).attr("href"));
location.href = $(this).attr("href");
});
});
HTML code
<li id="item-126" class="item-126 deeper parent">
<span class="nav-header">About Us</span>
<ul class="nav-child unstyled small">
<li id="item-129" class="item-129"><a href="/v1/index.php/aboutus/bio">Bio</a> </li>
<li id="item-130" class="item-130"><a href="/v1/index.php/aboutus/our-clients">Our Clients</a></li>
</ul>
</li>
<li id="item-127" class="item-127"><span class="nav-header">Services</span></li>
<li id="item-128" class="item-128"><span class="nav-header">Contact Us</span></li>
What I am trying to achieve is to animate the menu using the class up then open the link in item-129.
Any help is much appreciated.
Thanks