JavaScript Jquery And Bootstrap.js - DIV would show but not hide

I am using the Bootstrap CSS and JS libraries in my site and the following code:

$(function(){
$("#nav-login-btn").click(function(){
    if($("#togglesection").not(":visible")) {
        $("#nav-login-btn").css({"background-color":"#fff", "color":"#222"});
        $("#togglesection").show();
    }
    else {
        $("#nav-login-btn").css({"background-color":"transparent", "color":"#fff"});
        $("#togglesection").hide();
    }
})
})
$(document).mouseup(function (e)
{
    if (!$("#togglesection").is(e.target) && $("#togglesection").has(e.target).length === 0)
    {
        $("#togglesection").hide();
        $("#nav-login-btn").css({"background-color":"transparent", "color":"#fff"});
    }
});

The div would show and #nav-login-btn's css would change but then the else statement won't execute if I hit the button again. But the bottom code does hide my div if I click away. What is the problem?

Here is the jsfiddle: http://jsfiddle.net/Zmzk9

Answer:1

Try if(!$("#togglesection").is(":visible")) {

See this jsFiddle for more details...

In the console you'll notice that console.log($("#togglesection").is(":visible")); returns a boolean, whilst console.log($("#togglesection").not(":visible")); returns and actual object.

Answer:2

i would like to add comfirmationbox in durandal.js i wrote following to code , but it is not returning Yes or NO define(['services/logger', 'durandal/plugins/router', 'durandal/app'], function (...

i would like to add comfirmationbox in durandal.js i wrote following to code , but it is not returning Yes or NO define(['services/logger', 'durandal/plugins/router', 'durandal/app'], function (...

I'm trying to do a CORS on ie9 using ie9proxy.html: <!DOCTYPE HTML> <script src="https://apiurl/Content/xdomain.min.js"></script> "xdomain: Timeout waiting on iframe socket" ...

I'm trying to do a CORS on ie9 using ie9proxy.html: <!DOCTYPE HTML> <script src="https://apiurl/Content/xdomain.min.js"></script> "xdomain: Timeout waiting on iframe socket" ...

i have a class called .content , this content has an attribute called .data-time, i want to hide all element where it has .content class with setTimeout() function, anybody can help me? HTML code : &...

i have a class called .content , this content has an attribute called .data-time, i want to hide all element where it has .content class with setTimeout() function, anybody can help me? HTML code : &...

  1. multiple settimeout jquery
  2. settimeout jquery multiple function

I.m using ChartJs for "doughnut-pie-chart". The default radius is much bigger than what I expect,. Is there and way to resize the radius width.? The documentatin part did not provide any info. $( ...

I.m using ChartJs for "doughnut-pie-chart". The default radius is much bigger than what I expect,. Is there and way to resize the radius width.? The documentatin part did not provide any info. $( ...