Need a little help with accordion menu
Hello,
Totaly new in jquery here and I need a little help.
So I have one accordion menu which is working but I have to add one function. Now when I click on menu item is open properly but if doesn't close if I click again on the item. For example I have:
- Item1-head
- - sub-item1
- - sub-item2
I want when I click on item1-head to open and if I click again on item1-head to close. Now only is opening..
Here is the code
- $(document).ready(function () {
- $('#nav > li > a').click(function(e){
- if ($(this).attr('class') != 'active'){
- $('#nav li ul').slideUp();
- $(this).next().slideToggle();
- $('#nav li a').removeClass('active');
- $(this).addClass('active');
- }
- e.preventDefault();
- });
- });