Link to home
Start Free TrialLog in
Avatar of Jen0910
Jen0910Flag for United States of America

asked on

JQuery Toggle-How do I tell if all toggled elements are hidden?

Hello Experts,

I have a (hopefully) fairly simple question. Below i have a simple JQuery toggle menu for a recipe display which actually functions quite nicely for what we need, and ties in with a print stylesheet. We had this page done and the client added an advertisement to the side of the page, "recipe-call". Since all recipes have images that pop up on the same side, we need to hide the "recipe-call" div when someone clicks on a recipe title to display it. We have that function done just fine. As it stands, "recipe-call" is absolutely positioned and everything is fine with it, but what we need to do is get it to show up again when all of the recipes are collapsed. How would we test to see if all of the DIV elements are collapsed? Would this be a simple IF statement? I've tried a few things and so far it's been a no-go.

<script type="text/javascript">
         $(document).ready(function() {
  			$('div#recipe-show> div').hide();  
  			$('div#recipe-show> h2').click(function() {
				$('div#recipe-call').hide();
    			$(this).next('div').slideToggle('slow')
    			.siblings('div:visible').slideUp('slow');
  			});
		});
</script>

<div id="recipe-call">
        <img src="images/picture.jpg" width="259" height="196" />
        
        <div id="callout">
        <h4>Download award-winning <br>
        recipes here!</h4>
        </div>
</div>


<div id="recipe-show">
<h2>Title one</h2>
<div class="print-div">Content one</div>
<h2>Title two</h2>
<div class="print-div">Content two</div>
etc...
</div>

Open in new window


I'm a beginner with JQuery but not a beginner with development/code. Thanks in advance for your thoughts!
Avatar of leakim971
leakim971
Flag of Guadeloupe image

var all_Toggled_Element_Is_Hidden_FLAG = ( $("h2","div#recipe-show").next("div:hidden").length == $("h2","div#recipe-show").length ); // true or false
Avatar of Jen0910

ASKER

Thanks leakim971! Unfortunately, I'm having no luck. Would it work something like this:

<script type="text/javascript">
		var all_Toggled_Element_Is_Hidden_FLAG = ( $("h2","div#recipe-show").next("div:hidden").length == $("h2","div#recipe-show").length ); // true or false
		
         $(document).ready(function() {
  			$('div#recipe-show> div').hide();  
  			$('div#recipe-show> h2').click(function() {
				$('div#recipe-call').hide();
    			$(this).next('div').slideToggle('slow')
    			.siblings('div:visible').slideUp('slow');
  			});
			
			if(all_Toggled_Element_Is_Hidden_FLAG === true ) {
    			$('div#recipe-call').show();
				}
		});
</script>

Open in new window


Or am I implementing wrong?
ASKER CERTIFIED SOLUTION
Avatar of leakim971
leakim971
Flag of Guadeloupe image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial