Go Back   CodingForums.com > :: Client side development > HTML & CSS

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-28-2013, 02:32 AM   PM User | #1
marcy84
New to the CF scene

 
Join Date: Jan 2013
Posts: 8
Thanks: 2
Thanked 0 Times in 0 Posts
marcy84 is an unknown quantity at this point
Need css code to close subcategories on click

I recently added a vertical accordion menu to my website but I'm having trouble trying to figure out how to close the headers on click. Here is the jquery code that should enable that function (but it doesn't):

[<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script type="text/javascript">

$(document).ready(function() {

// Store variables

var accordion_head = $('.accordion > li > a'),
accordion_body = $('.accordion li > .sub-menu');

// Open the first tab on load

accordion_head.first().addClass('active').next().slideDown('normal');

// Click function

accordion_head.on('click', function(event) {

// Disable header links

event.preventDefault();

// Show and hide the tabs on click

if ($(this).attr('class') != 'active'){
accordion_body.slideUp('normal');
$(this).next().stop(true,true).slideToggle('normal');
accordion_head.removeClass('active');
$(this).addClass('active');
}

});

});]

I'm at a loss, Any advice would be appreciated!
marcy84 is offline   Reply With Quote
Old 01-28-2013, 08:29 PM   PM User | #2
marcy84
New to the CF scene

 
Join Date: Jan 2013
Posts: 8
Thanks: 2
Thanked 0 Times in 0 Posts
marcy84 is an unknown quantity at this point
Anybody?
marcy84 is offline   Reply With Quote
Old 01-28-2013, 08:40 PM   PM User | #3
teedoff
Senior Coder

 
Join Date: Aug 2010
Location: High Point, NC
Posts: 3,325
Thanks: 5
Thanked 363 Times in 360 Posts
teedoff is on a distinguished road
Looks like you dont give enough info for anyone to help. Do you have a link to your site? All you've posted is the js. Where is the element that you're adding a class of active too? Where is the css associated with .active?
__________________
Teed
teedoff is offline   Reply With Quote
Reply

Bookmarks

Tags
close on click, header, jquery, menu, navigation

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 04:56 AM.


Advertisement
Log in to turn off these ads.