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 3596202
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T19:57:27+00:00 2026-05-18T19:57:27+00:00

I’m still quite new with jQuery, I know that I could google and have

  • 0

I’m still quite new with jQuery, I know that I could “google” and have something very similar up and running in 5 mins, but I’m learning – I need to make the mistakes and ask!

I was sure this should work but the last step didn’t.. If someone has a way of creating this effect or knows how to clean-up my code it would be much appreciated but more so if someone could tell me where I have gone wrong..

    //intial load
$(document).ready(function(){

    // row has been clicked
    $(".fp_row").bind('click', function(){

        //row id has been set to item_clicked
        var item_clicked = $(this).attr('rel');
        //Item_hidden is the div that shows or hides, like accordion menu
        var item_hidden = $("#" + item_clicked + "_hide").attr('rel');

        //hide all that are open, and then toggle the one you clicked..
        $(".fp_dropdown_box").slideUp("slow", function(){
            $("#" + item_hidden + "_hide").not(".fp_dropdown_box").slideToggle("slow");
        });

    });


});

I’m making a page with rows of headlines, when you click a row a div slides out revealing more information, just like an accordion. I can currently make the box you click on open and all others close. I can make all open at once and close at once.. But I am having problems making one open then if you click it again it closes,currently It slides up and then down again.

How I thought the code above worked..
On initial load, when a row is clicked grab the rel value (which is what I’m using for a unique identifier for each row) then slide-up all rows that are currently open but not the one you have clicked on toggle slide this..

<!--- row --->
    <div id="1_row" class="fp_row clearfix" rel="1">
        <!--- time --->
        <div class="fp_col fp_col_time"><p>the time</p></div>
        <!--- title --->
        <div class="fp_col fp_col_title"><p>the title</p></div>
    </div>

    <!--- hidden information --->
    <div id="1_hide" rel="1" class="fp_dropdown_box clearfix" style="<cfif qEvents.event_id EQ url.event_id>display:;<cfelse>display:none</cfif>" > 
        <div class="fp_dropdown_content"><p>the hidden information</p></div>
    </div>

Ok so after the comments, I managed to get the script to somewhat work – the only problem left is that it opens then closes twice before stopping at the state I want it to be..

Updated Code.

    //intial load
$(document).ready(function(){

    // row has been clicked
    $(".fp_row").bind('click', function(){

        //The Id of the clicked Row
        var item_clicked = $(this).attr('rel');
        console.log("The ID of the clicked Row: (" + item_clicked + ")");

        //Creates variable ID for the hidden item
        var item_hidden = $("#" + item_clicked + "_hide").attr('rel');
        console.log("The Hidden Item ID (" + item_hidden + ")");

        //Creates variable to test if the hidden item is true or false.
        var item_is_hidden = $("#" + item_hidden + "_hide").css('display') == 'none';
        console.log("test if hidden item is hidden (" + item_is_hidden +")");

            //slide up all that are open
            $(".fp_dropdown_box").slideUp("slow", function(){
                //test to see if it is open: true/false
                 if(item_is_hidden)
                    {
                    console.log("condition worked!");
                    //Run the slidedown on hidden item
                        $("#" + item_hidden + "_hide").slideDown("slow");
                    }
                else
                       {
                    $("#" + item_hidden + "_hide").slideUp("slow");
                    }
            });
    });
});

this is my final edit, I think this was the cleanest way

$(document).ready(function() {

    $('div.cont > div').hide(); 

    $('div.cont> h3').click(function() {
        $(this).next('div').slideToggle('fast').siblings('div:visible').slideUp('fast');
    });
});
  • 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-05-18T19:57:27+00:00Added an answer on May 18, 2026 at 7:57 pm

    The problem is just that you hide them all, then toggle the clicked one – so it will always be shown. You need to detect whether it’s shown or not and act appropriately.

    var item_hidden = $("#" + item_clicked + "_hide").attr('rel');
    var item_is_hidden = $("#" + item_hidden + "_hide").css('display') == 'none';
    
    $(".fp_dropdown_box").slideUp("slow", function(){
        if(item_is_hidden)
           $("#" + item_hidden + "_hide").slideToggle("slow");
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a French site that I want to parse, but am running into
I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a small JavaScript validation script that validates inputs based on Regex. I
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
This could be a duplicate question, but I have no idea what search terms
I know there's a lot of other questions out there that deal with this
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i

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.