Collapsed By Default

+1 Kaveh Greenwood · September 8, 2014
I have this script on my page that allows me to expand and collapse pieces of an unordered list. I'd like to have each section collapsed by default.

Could anyone provide any input on what I can do?


    $(document).ready(function(){

      $('#customPricing > ul > li:has(ul)').addClass("has-sub");

      $('#customPricing > ul > li > a').click(function() {
        var checkElement = $(this).next();
        
        $('#customPricing li').removeClass('active');
        $(this).closest('li').addClass('active');   
        
        
        if((checkElement.is('ul')) && (checkElement.is(':visible'))) {
          $(this).closest('li').removeClass('active');
          checkElement.slideUp('normal');
        }
        
        if((checkElement.is('ul')) && (!checkElement.is(':visible'))) {
          $('#customPricing ul ul:visible').slideUp('normal');
          checkElement.slideDown('normal');
        }
        
        if (checkElement.is('ul')) {
          return false;
        } else {
          return true;  
        }       
      });

    });

Post a Reply

Replies

Oldest  Newest  Rating
0 Çağlan Turgut · September 10, 2014
I think being impatient is better so that people who has the same problem can see how you solved the problem :).
+2 Kaveh Greenwood · September 8, 2014
I solved my own problem again, haha. Just takes time. I get too impatient and post in the forums, but once I slow my mind down and do some research I learn what the problem is.

It wasn't even with the jQuery, it was CSS, haha.

#customPricing ul ul{
display: none;
}
  • 1

Javascript

107,064 followers
About

A scripting language that is added to standard HTML to create interactive effects, apps, games for the browser.

Links
Moderators