Solved

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

Posted on 2012-03-31
1
458 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

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

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 article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
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)

687 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