0

I have a panel with 3 buttons. Currently I have it so that if you click one of the 3 buttons, it toggles a hidden DIV ("#utilityBK") show and then to animate from the bottom and slide up. I need to add some logic to the function to determine if "#utilityBK" is already showing, and if it is, just to swap out different DIVs that's contained within. Here is the HTML

<div id="utilityBK">
<div id="chatContent"></div>
<div id="locationsContent"></div>
<div id="searchContent"></div>
</div>

Here's one of the functions that currently works just to toggle the utilityBK and that's it.

$(document).ready(function(){
    ("#chat").click(function(){
       if ($("#utilityBK").is(":hidden")) {
          $("#utilityBK").animate({'bottom': '60px'}, 'slow');
          $('body').addClass('noscroll');
       } 
    else {
       $("#utilityBK").animate({'bottom': '-325px'}, 'slow');
       $('body').removeClass('noscroll');
         } 
    }); 
});

And then this is my attempt on adding the additional logic to check to see if #utilityBK, #searchContent or #chatContent is displayed. If so, I just want it to hide those *Content IDs and display the #locationsContent DIV, otherwise animate the #utilityBK back down.

$(document).ready(function(){
$("#locations").click(function(){
  if ($("#utilityBK").is(":hidden")) {
   $("#utilityBK").animate({'bottom': '60px'}, 'slow');
   $('body').addClass('noscroll');
} 
else  if ($("#searchContent, #chatContent, #utilityNav").not(":hidden")) {
    $("#searchContent").css("display","none");
    $("#chatContent").css("display","none");
    $("#locationsContent").css("display","block");  
} else {
    $("#utilityBK").animate({'bottom': '-325px'}, 'slow');
    $('body').removeClass('noscroll');
} 
}); 
});

So at the moment that particular button doesn't do anything... I'm guessing I'm not structuring the else if statement they way I intend it to work.

2 Answers 2

1

.not() doesn't return true/false like .is(). It returns a jQuery collection. If you want to test whether there are any elements in the collection, use .length:

if ($("#searchContent, #chatContent, #utilityNav").not(":hidden").length > 0)
Sign up to request clarification or add additional context in comments.

Comments

0

Try this

// Matches #utilityBK element that are hidden
$('#utilityBK:hidden').length > 0

Instead of $("#utilityBK").is(":hidden")

Update:

Demo link http://jsfiddle.net/dhana36/YT3CD/1/

I have imagined you are trying to hide the div like this,

$(document).ready(function(){
    $("#chat").on('click', function(){
       $("#utilityBK").toggle('slow');
        });
});

2 Comments

Result will be same either way.
No, still does not answer the question.

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.