0

I need a js script show / hide with only shown one div at time others closed. By default any (only one) must be shown.

I have got this script: http://jsfiddle.net/kolxoznik1/BFV9k/.

I want to add some class like show:

 <div class="toggle show">Content</div>

If show will be added div will not be hided, he will heve status show() othervise all divs will be hide().

Suppose someone will help me with my small problem.

1
  • 2
    the method you got right now is correct, if you hide the divs what are you gonna click on to show? 0_o Commented Aug 19, 2011 at 19:13

2 Answers 2

1

If you mean the last active element shouldn't hide, then try this:

$(document).ready(function() {
    $(".toggle").click(function() {
        if(!$(this).hasClass('active')){
            $('.active').not(this).toggleClass('active').next('.hidden').slideToggle(300);
            $(this).toggleClass('active').next().slideToggle("fast");
        }
    }).next(".hidden").hide();
});

Here is a forked demo of your version.

Sign up to request clarification or add additional context in comments.

1 Comment

@Viktors Golubevs: I do not understand you buddy. Are you trying to show multiple elements?
0
$("div").hide();
$(".show").show();

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.