www.webdeveloper.com
Results 1 to 3 of 3

Thread: Accordion Script

  1. #1
    Join Date
    Aug 2013
    Posts
    4

    Accordion Script

    Hi - I'm using this script for an accordion on a website. I'd like to know if it's possible to amend the script so that when the title of each accordion block is clicked on the block will closed again? Currently each accordion block only closes when the title of another accordion block is clicked on.

    /*Accordion*/
    $('.accordion ul').hide();
    $('.accordion li:first').find('a.title').addClass('tab-active');
    $('.accordion ul:first').hide();
    $('.accordion li a.title').click(

    function() {
    var checkElement = $(this).next();
    if ((checkElement.is('ul')) && (checkElement.is(':visible'))) {
    $('accordion').find('a.title').removeClass('tab-active');
    return false;
    }
    if ((checkElement.is('ul')) && (!checkElement.is(':visible'))) {
    $('.accordion ul:visible').slideUp(500);
    checkElement.slideDown(500);
    $('.accordion').find('a.title').removeClass('tab-active');
    $(this).addClass('tab-active');
    return false;
    }
    });


    I'm new to JS so would really appreciate any help! Many thanks.

  2. #2
    Join Date
    Mar 2007
    Location
    localhost
    Posts
    2,304
    1. its not JavaScript
    2. your code needs to be in [ CODE ] tags to help people to help you
    3. when starting to use JS, use it, not JQuery.
    Yes, I know I'm about as subtle as being hit by a bus..(\\.\ Aug08)
    Yep... I say it like I see it, even if it is like a baseball bat in the nutz... (\\.\ Aug08)
    I want to leave this world the same way I came into it, Screaming, Incontinent & No memory!
    I laughed that hard I burst my colostomy bag... (\\.\ May03)
    Life for some is like a car accident... Mine is like a motorway pile up...

    Problems with Vista? :: Getting Cryptic wid it. :: The 'C' word! :: Whois?

  3. #3
    Join Date
    Dec 2005
    Location
    FL
    Posts
    7,364
    It is also a good idea to include any HTML and CSS to show intent of JS actions.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles