Solved

Custom JQuery accordion - need help setting first item to be open by default.

Posted on 2012-03-31
1
451 Views
Last Modified: 2012-04-11
Hi,

Found the following accordion example online, works great however I want it to be open at the first item by default. How can I modify code below to allow first item to be open?


<script language="javascript" type="text/javascript">
        $(document).ready(function () {
            //ACCORDION BUTTON ACTION      
            $('div.accordionButton').on('click',function () {
                $('div.accordionContent').slideUp('normal');
                $(this).next().slideDown('normal');
            });

            //HIDE THE DIVS ON PAGE LOAD      
            $("div.accordionContent").hide();

        });
      </script>


<div id="acc-wrapper">
            <div class="accordionButton">Item1</div>
            <div class="accordionContent">Content 1<br /><br /><br /><br /><br /><br /><br /><br />Long Example</div>
            <div class="accordionButton">Item2</div>
            <div class="accordionContent">Content 2<br /><br /><br /><br /><br />Medium Example</div>
            <div class="accordionButton">Item3</div>
            <div class="accordionContent">Content 1<br />Short Example</div>
            <div class="accordionButton">Item4</div>
            <div class="accordionContent">Content 4<br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br />Extra Long Example</div>
      </div>
0
Comment
Question by:jazz__man
1 Comment
 
LVL 3

Accepted Solution

by:
animecyc earned 500 total points
ID: 37791937
In your javascript change:

$("div.accordionContent").hide();

Open in new window


to:

$("div.accordionContent").not(':first').hide();

Open in new window

0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
Introduction JSON is an acronym for JavaScript Object Notation.  It is a text-string data transport mechanism, capable of representing simple or complex data structures in a consistent and easy-to-read manner.  Similar in concept to XML, but more e…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

860 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question