Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7173141
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T15:45:42+00:00 2026-05-28T15:45:42+00:00

I have a little problem with a navigation I’m making. I want my navigation

  • 0

I have a little problem with a navigation I’m making.

I want my navigation to slidedown with submenus and not link to anything, if they have childrens. And if a child is active (), then the parent should be active too, and automaticly show the children.
So far I made this work.

Now I want the parents to change class, if you click them. Toggle between .active and the ordinary style. I can only get the standard links to do so, and if you click a parent who’s not active, the parent who is active should slide up the children and become deactivated.

Anyone who can help me with this issue?

My code so far looks like this:

<ul class="menu collapsible expandactive" id="products">
  <li class="item"><a href="#" >Tryksager</a>
    <ul>
      <li><a href="#">A3 / A4 Plakater</a></li>
      <li><a href="#">Blokke</a></li>
      <li><a href="#">Brevpapir</a></li>
      <li><a href="#">Flyers / l&oslash;sark</a></li>
      <li><a href="#">Foldere</a></li>
      <li><a href="#">Kuverter</a></li>
      <li><a href="#">Visitkort</a></li>
    </ul>
  </li>
  <li class="item active parent"><a href="#" >Storformat print</a>
    <ul>
      <li><a href="#">Plakater</a></li>
      <li><a href="#">Canvas / L&aelig;rred</a></li>
      <li class="active"><a href="#">Klisterm&aelig;rker</a></li>
      <li><a href="#">Folie</a></li>
      <li><a href="#">Rollup System</a></li>
    </ul>
  </li>
  <li class="item"><a href="#" >Grafisk Design</a></li>
  <li class="item"><a href="#" >Hjemmesider</a></li>
  <li class="item"><a href="#" >G&oslash;r Det Selv</a></li>
  <li class="item"><a href="#" >Om Trykkeriet</a></li>
  <li class="item"><a href="#" >Diverse</a></li>
</ul>

And my jQuery looks like this:

function initProducts() {
$('ul#products ul').hide();
$.each($('ul#products'), function(){
    $('#' + this.id + '.expandactive li.active ul').show();
});
$('ul#products li a').click(
    function() {
        var checkElement = $(this).next();
        var parent = this.parentNode.parentNode.id;

        if($('#' + parent).hasClass('noaccordion')) {
            $(this).next().slideToggle('normal').removeClass('active');
            return false;
        }
        if((checkElement.is('ul')) && (checkElement.is(':visible'))) {
            if($('#' + parent).hasClass('collapsible')) {
                $('#' + parent + ' ul:visible').slideUp('normal');
            }
            return false;
        }
        if((checkElement.is('ul')) && (!checkElement.is(':visible'))) {
            $('#' + parent + ' ul:visible').slideUp('normal');
            checkElement.slideDown('normal');
            return false;
        }
    }
);
}
$(document).ready(function() {initProducts();});
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T15:45:42+00:00Added an answer on May 28, 2026 at 3:45 pm

    I’m not absolutely sure what you’re aiming to achieve. However if it’s simply that you’d like to change only the parents class to active then this should do the trick:

    function initProducts() {
        $('ul#products ul').hide();
        $.each($('ul#products'), function(){
            $('#' + this.id + '.expandactive li.active ul').show();
        });
        $('ul#products li a').click(
            function() {
                var checkElement = $(this).next();
                var parent = this.parentNode.parentNode.id;
    
                if($('#' + parent).hasClass('noaccordion')) {
                    $(this).next().slideToggle('normal').removeClass('active');
                    return false;
                }
                if((checkElement.is('ul')) && (checkElement.is(':visible'))) {
                    if($('#' + parent).hasClass('collapsible')) {
                        $('#' + parent + ' ul:visible').slideUp('normal');
    
                        // ADDED CODE
                        $(this).parent().removeClass("active");
                        $(this).parent().find("li").removeClass("active");
                        // END
                    }
                    return false;
                }
                if((checkElement.is('ul')) && (!checkElement.is(':visible'))) {
                    $('#' + parent + ' ul:visible').slideUp('normal');
                    checkElement.slideDown('normal');
    
                    // ADDED CODE
                    $(this).parent().addClass("active");
                    // END
    
                    return false;
                }
            }
        );
    }
    

    Here’s a jsfiddle for you: http://jsfiddle.net/XHCpg/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a little problem with the library 'Telerik'. Indeed I want to implement
I need a little help on a problem with navigation controllers. I have a
I've got a problem with a little project. I have a navigation bar that
I'm making an PhoneGap app using Jquery Mobile, but I have a little problem
I have a little problem with jquery and a div menu that is not
I have little problem with a replacement of a little part in an url.
I have little problem in regular expressin creation. Expected input: blahblahblah, blahblahblah, 'blahblahblah', blahblahblah,
I have little unusual problem to solve. I need some hint or links to
I have a little problem about the sort direction of a specific column in
I have a little problem with Jquery getJSON function. my json here { entries:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.