0

I have some divs that need to be hidden (class named .hideable), and some divs that need to be shown (class named .toggleable. I have it working so far, which is great, but I`m having difficulties with the following; The hidden divs (.hideable) need to come back after the toggleable divs are hidden again.

here is what I have:

jQuery(document).ready(function($) {
    var topContainer = $(".toggleable");
    var topButton = $(".orsp a");
    topButton.click(function() {
        topContainer.slideToggle('slow');
        $(".hideable").hide();
    });
});

all help is welcome! thanks, J.

5
  • Can you show your html Commented Sep 15, 2013 at 11:06
  • 3
    Can you post a working example in a jsfiddle.net Commented Sep 15, 2013 at 11:06
  • why is there need for html? Commented Sep 15, 2013 at 11:18
  • @Jonathan79 to understand the problem as your code seems to be correct Commented Sep 15, 2013 at 11:19
  • thanks guys for helping out. I see how jsfiddle can help, but for this problem, it was only about the jquery. Thanks again! Commented Sep 15, 2013 at 11:23

5 Answers 5

2

Use jQuery.toggle()

$(".hideable").toggle();

instead of jQuery.hide()

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

Comments

0

I think you wnat try like this

HTML

<div style='display:none' class='hideable' >Hidden Div</div>
<div class='toggleable'>Toggleable div</div>

<input class='topButton' type='button' value='toggle'>

JS

$('.topButton').click(function() {
    $('.toggleable').slideToggle('slow', function() { $(".hideable").slideToggle(); });
});

Fiddle Here

Comments

0

If you don't want to use toggle to hide the .hideable div you can hide it using CSS and whenever you toggle .toggleable div you can check with Jquery whether it is hidden and if it is you can change it back to be shown. However Jakub's answer is the simplest solution.

Comments

0
jQuery(document).ready(function($) {
var topContainer = $(".toggleable");
var topButton = $(".orsp a");
topButton.toggle(function() {
    topContainer.slideToggle('slow');
    $(".hideable").hide();
},function () {
topContainer.slideToggle('slow');
    $(".toggleable").hide();
 });
});

Comments

0

Simplest choose toggle or toggle class

Fiddle

<http://jsfiddle.net/gcsHg/>?

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.