Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7987547
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T12:10:52+00:00 2026-06-04T12:10:52+00:00

I have a Javascript Accordiong, currently it displays the first dd when page is

  • 0

I have a Javascript Accordiong, currently it displays the first dd when page is loaded, then when you click on a dt tag, the dd that is open should close and the dd tag within the dt clicked show slidedown.

However atm the first dd is shown on load, the open dd closes when another dt is clicked, but the next dd doesnt show.

Can someone please help me :/

My JS:

//Accordion  - Hides open, and opens the clicked
    $(document).ready(function() {
        $('dd:not(:first)').hide(); //hides all but the first dd (the content under the headings)
        $('dt').click(function() {
            $('dd').slideUp('slow'); //slides up current dd 
            $(this).parent('dt').next('dd').slideDown('slow');
        });
    });

This is my html:

 <!DOCTYPE HTML>
<html>
<head>
    <title>Hobbies</title>
    <script src="js/jquery.js" type="text/javascript"></script>
    <script type="text/javascript" src="js/jscript.js"></script>
    <link rel="stylesheet" href="style\main.css" media="screen" />
</head>
<body>
<div id="container">
        <a name="top"></a>
    <div>
        <ul class="menu">
            <li><a href="index.html">Home</a></li>
            <li><a href="schedule.html">Schedule</a></li>
            <li><a href="resume.html">Resume</a></li>
            <li><a href="contact.html">Contact</a></li>
            <li><a href="hobbies.html">Hobbies</a>
                <ul>
                    <li><a href="hobbies.html#uni">University</a></li>
                    <li><a href="hobbies.html#games">Gaming</a></li>
                    <li><a href="hobbies.html#chess">Chess</a></li>
                    <li><a href="hobbies.html#golf">Golf</a></li>
                    <li><a href="hobbies.html#music">Harmonica</a></li>
                </ul>
            </li>
            <li><a href="image.html">Images</a></li>
        </ul>
    </div>
    <div id="contenthobby">
    <div>
    <dt><a name="uni"><h2>University</h2></a></dt>
        <dd>
        <div class="pa">
                <p> content
            </div>
            <div class="pic">
                <img src="http://physics.uq.edu.au/ap/cosmicflow/wp-content/uploads/2011/11/uq_logo.gif" 
                alt="Error Loading Image">
                <p>This is the UQ logo</p>
                <img src="http://maps.googleapis.com/maps/api/staticmap?center=-27.497899,153.013222&amp;zoom=16&amp;size=250x250&amp;markers=-27.497899,153.013222&amp;sensor=false" alt="The University of Queensland"/>
                <p>This is UQ</p>
            </div>
            <a href="#top">Return to Top</a>
        </dd>
    </div>
    <div>
    <dt><a name="games"><h2>Gaming</h2></a></dt>
        <dd>
        <div class="pa">
            <p>I love to play games, even though it wastes so much time and amounts to nothing.
            It allows me to just go into another world. Something amazing when your slaying dragons
            haha.</p>
            <p>SKYRIM!</p>
            <p>What I Like About it</p>
            <ol>
                <li>Able to immerse yourself into the game</li>
                <li>Gets the adrenalin pumping when your in an intense fight</li>
                <li>Allows for late night fun</li>
            </ol>
        </div>
        <div class="pic">
            <img src="http://www.darylh.com/images/articleimages/SkyrimLogo.png"
            alt="Error loading image: http://www.darylh.com/images/articleimages/SkyrimLogo.png">
            <p>This is the game logo for skyrim</p>
            <iframe width="320" height="240" src="http://www.youtube.com/embed/ARaOOKafLEw"></iframe>
            <p>This is a video of the fun shout in skyrim.</p>
        </div>
        <a href="#top">Return to Top</a>
        </dd>
    </div>
    <div>
    <dt><a name="chess"><h2>Chess</h2></a></dt>
        <dd>
        <div class="pa">
            <p> I love playing chess. It is a good way to unwind, will keeping your mind
            sharp. It allows you to hone your skills and adapt your way of thinking.</p>
            <p>Chess is a game played by men and boys alike, and this is why i believe 
            it is essential to a persons growth. Hence why I play it.</p>
            <p>What I Like About it</p>
            <ol>
                <li>Sharpens your mind</li>
                <li>Fun to work out the problem and beat your opponenet</li>
                <li>Gives you a clearer outlook on the world</li>
            </ol>
        </div>
        <div class="pic">
            <img src="http://www.graemeanthonypewter.com.au/uploads/image/Armageddon-Chess-Set-2.jpg" alt="chess" height="250" width="250">
            <p>This is an example of a chess set</p>
            <img src="http://upload.wikimedia.org/wikipedia/commons/7/71/ChessPawnSpecialMoves.gif" alt="chess board" width="250" height="250">
            <p>This is a chess move, used by pros</p>
        </div>
        <a href="#top">Return to Top</a>
        </dd>
    </div>
    <div>
    <dt><a name="golf"><h2>Golf</h2></a></dt>
        <dd>
        <div class="pa">
            <p>The sport of golf is one of majesty and finesse. It allows one to realise
            that one cannot focus on where he is, but where he is going, and how he is 
            going to get there!</p>
            <p>What I Like About It</p>
            <ol>
                <li>Its outdoors</li>
                <li>Is fun to play</li>
                <li>Get to drive around in the golf cart</li>
            </ol>   
        </div>
        <div class="pic">
            <img width="250" height="250" src="http://www.ashlargolfclub.com.au/upload/wysiwyg/whatsonIndex/Copy%20of%20Copy%20of%20Golf-Ball-and-Tee.jpg" alt="Golf ball">
            <p>This is a golf ball</p>
            <iframe width="250" height="200" src="http://maps.google.com.au/maps?q=54.909901,25.311652&amp;num=1&amp;t=h&amp;hl=en&amp;ie=UTF8&amp;z=14&amp;ll=54.91103,25.312715&amp;output=embed"></iframe><br /><small><a href="http://maps.google.com.au/maps?q=54.909901,25.311652&amp;num=1&amp;t=h&amp;hl=en&amp;ie=UTF8&amp;z=14&amp;ll=54.91103,25.312715&amp;source=embed" style="color:#0000FF;text-align:left">View Larger Map</a></small>
            <p>This is my favourite golf course</p>
        </div>
        <a href="#top">Return to Top</a>
        </dd>
    </div>
    <div>
    <dt><a name="music"><h2>Harmonica</h2></a></dt>
        <dd>
        <div class="pa">
            <p>I Love playing the harmonica, it allows me to just release my feelings 
            through music.</p>
            <p>It also allows me to learn control, in how to release air, and adjust my 
                mouth to get the perfect pitch and sound</p>
            <p>What I like About It</p>
            <ol>
                <li>Its a musically instrument</li>
                <li>It has soul</li>
                <li>It allows me to unwind after a hard day of work</li>
            </ol>
        </div>
        <div class="pic">
            <img width="250" height="250" src="http://www.harmonicagame.com/help/harmonica_tab_screen.gif" alt="Harmonica">
            <p>These are the chords of a harmonica</p>
            <img width="250" height="250" src="http://www.hoerl.com/Graphics/music_harm_hold.gif" alt="Proper way to hold">
            <p>How to Hold a Harmonica</p>
        </div>
        <a href="#top">Return to Top</a>
        </dd>
    </div>
    </div>
    <footer class="footer">

            <a href="http://jigsaw.w3.org/css-validator/check/referer">
                <img style="border:0;width:88px;height:31px"
                src="http://jigsaw.w3.org/css-validator/images/vcss"
                alt="Valid CSS!" />
            </a>
</footer>
</div>
</body>
</html>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T12:10:53+00:00Added an answer on June 4, 2026 at 12:10 pm

    Working demo http://jsfiddle.net/UL3V3/1/

    Good read: API : http://api.jquery.com/visible-selector/

    slideToggle http://api.jquery.com/?ns0=1&s=slideToggle&go=

    Using this you can close the open dd as well.

    Rest you can play around and find out the behavior.

    This will help. B-)

    Jquery code

      $(document).ready(function() {
            $('dd:not(:first)').hide(); //hides all but the first dd (the content under the headings)
            $('dt').click(function() {
             if ($(this).next('dd').is(":hidden"))
                $('dd').slideUp('slow');//slides up current dd 
    
                $(this).next('dd').slideToggle('slow');
    
    
            });
        });​
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have Javascript that opens another window and registers a click handler for all
I have JavaScript that is doing activity periodically. When the user is not looking
I have javascript string variable with var sttr=We prefer questions that can be answered
I have a web form that contains lots of JavaScript functionalities to manipulate the
Update Added jsfiddle - see bottom of post I currently have a function that
Do any of the currently popular browsers have particular problems caching* XMLHttpRequest responses that
I have javascript code embedded inside a html template file. When I load this
I have JavaScript code which copies the value of input file and paste it
I have JavaScript form validation functions like so: function validate_name(field) { if (field ==
I have JavaScript of ajax uploader as below; $(document).ready(function(){ var qwerty = $('#qwerty').val(); $('#demo1').ajaxupload({

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.