I am attempting to build a Jquery/CSS drop down menu and things have been going pretty good so far. I'm pretty new to JQuery and I get it most of the time - however, I cannot figure out what I am doing wrong here.
I am attempting to change the class of one of the drop-down tabs when it is clicked, but it doesn't appear to be working as expected.
You can see the code I have so far over here: http://jsfiddle.net/utdream/NZJXq/
I have the class "selected" looking how I want the button to look when a button is clicked on, but I cannot seem to make it so the "selected" class is applied on a click event. In theory, this:
<li id="menuProducts"><a href="#" class="hasmore">Products</a>
<div id="ProductsMenu">
<ul>
<li><a href="#">Submenu Item</a></li>
<li><a href="#">Submenu Item</a></li>
</ul>
</div>
</li>
Should change this this on a click event:
<li id="menuProducts"><a href="#" class="selected">Products</a>
<div id="ProductsMenu">
<ul>
<li><a href="#">Submenu Item</a></li>
<li><a href="#">Submenu Item</a></li>
</ul>
</div>
</li>
And this is my current jQuery (which doesn't work):
jQuery(document).ready(function () {
$('#menuProducts a:first').on('click',
function () {
$("a:first").removeClass("hasmore");
$("a:first").addClass("selected");
menuSubCloseAll.call(this, 'menuProducts');
$('#menuProducts').find('li').slideToggle(200);
});
});
I've tried rewriting this code in many,many different ways and I'm running out of ideas on what I could be doing wrong.
Anyone out there have any pointers on what I could do to fix this?
Thank you in advance!!
$("a:first")with$(this).