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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T04:11:10+00:00 2026-06-12T04:11:10+00:00

you know how you open a hide\show spoiler and then open another one and

  • 0

you know how you open a hide\show spoiler and then open another one and it makes the page really long ?

the solution for it is to make the js check if the class is showing, if yes close the spoiler.

But im not sure how to do this.
This is the js code im using:

$(document).ready(function(){


    $(".hide1").hide();
    $(".spoiler1").show();

    $('.spoiler1').click(function(){
    $(".hide1").slideToggle();
    });

});

hide1 = the content that opens on click
spoiler1 = the toggle button.

Spoiler2, 3, 4 are the rest spoilers
so is hide2,3,4 are the rest contents.

this is the live site:

http://justxp.plutohost.net/slyfiles/index.html

EXAMPLE:

You click on the first box
this is the boxs area by the way:

http://gyazo.com/5df95ee77b95dfd932eab781955f98f3.png?1349209216

okay, it opened, then click on the second one..
And the content opens yet the first box hasn’t closed.

I want the first box to close after opening a new one.
to work like this for all boxs.

how do I do so?

Sorry for the awful grammar by the way.

Thanks!

  • 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-12T04:11:11+00:00Added an answer on June 12, 2026 at 4:11 am

    You should link each spoiler to its corresponding hide via custom property:

    <div id="spoiler1" data-hidden="hide1" class="spoiler">Spoiler 1</div>
    <div id="hide1" class="hide">Hide 1</div>
    <div id="spoiler2" data-hidden="hide2" class="spoiler">Spoiler 2</div>
    <div id="hide2" class="hide">Hide 2</div>
    <div id="spoiler3" data-hidden="hide3" class="spoiler">Spoiler 3</div>
    <div id="hide3" class="hide">Hide 3</div>
    <div id="spoiler4" data-hidden="hide4" class="spoiler">Spoiler 4</div>
    <div id="hide4" class="hide">Hide 4</div>​
    

    The the behavior would be this:

    $('.spoiler').click(function() {
        var hiddenid = $(this).data('hidden');
        $('#' + hiddenid).slideToggle();
        $('.hide:not(#' + hiddenid + ')').slideUp();
    });​
    

    See working fiddle: http://jsfiddle.net/adrianonantua/dyUwH/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know that being open source does not necessarily makes a program more/less secure
I'm working with jstree and I would like to know how to hide/show nodes
Does anyone know any open source project or adapter for MySQL-AdWhirl? We try to
my site www.theprinterdepo.com its a magento oscommerce site As you know its open source,
I know how to open an URL from app in Safari using [[UIApplication sharedApplication]
does aybody know about an open source sound library in C++ or some other
Do you know about any open source projects written in XQuery? The larger the
Does anyone know of an open source/free tool for converting pl/sql code to a
I just want to know how to open webCam in Js but i don't
Firefox doesn't know how to open this address because the protocol (c) isn't associated

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.