Solved

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

Posted on 2012-03-31
1
443 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Introduction Got endorsements from your clients?  Great!  There is almost nothing better than word-of-mouth advertising.  But how can you do that on the internet?  Sure you can make a page for endorsement quotations and list them all, but who is …
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 …
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. 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.: (CODE)

759 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now